1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
protected void BTN_send_shift_Click(object sender, EventArgs e)
{
string filepath = "xxxxxxxxxxxxxxxxxxxxxxxx.txt";
List<string[]> parsedData = new List<string[]>();
using (StreamReader readFile = new StreamReader(filepath))
{
string line;
string[] row;
Regex r = new Regex(" +");
while ((line = readFile.ReadLine()) != null)
{
row = r.Split(line);
parsedData.Add(row);
}
}
bool i = true;
List<string> dbOperations = new List<string>();
char header2 ='X';
char header3 ='X';
char header4 ='X';
char header5 ='X';
char header6 ='X';
char header7 ='X';
char header = 'X';
string Sql_RotID = "Select MAX(ROT_ID) from ROTATION"; //Je selectionne la derniere ID
SqlCommand cmd_RotID = new SqlCommand();
cmd_RotID.Connection = Connection;
cmd_RotID.CommandText = Sql_RotID;
int RotID = 0;
Connection.Close();
Connection.Open();
object rotObj = cmd_RotID.ExecuteScalar();
if (rotObj.GetType() != typeof(DBNull))
{
RotID = Convert.ToInt32(rotObj);
}
Connection.Close();
foreach (string[] row in parsedData)
{
if (i)
{
header2 = Convert.ToChar(row[2]);
header3 = Convert.ToChar(row[3]);
header4 = Convert.ToChar(row[4]);
header5 = Convert.ToChar(row[5]);
header6 = Convert.ToChar(row[6]);
header7 = Convert.ToChar(row[7]);
i = false;
}
else
{
string val0 = row[0];
string val1 = row[1];
string val2 = row[2];
string val3 = row[3];
string val4 = row[4];
string val5 = row[5];
string val6 = row[6];
string val7 = row[7];
if(val0 == "jan") {val0 = "01";}
else if (val0 == "feb") {val0 = "02";}
else if(val0 == "mar") {val0 = "03";}
else if (val0 == "apr") {val0 = "04";}
else if(val0 == "may") {val0 = "05";}
else if (val0 == "jun") {val0 = "06";}
else if(val0 == "jul") {val0 = "07";}
else if (val0 == "aug") {val0 = "08";}
else if(val0 == "sep") {val0 = "09";}
else if (val0 == "oct") {val0 = "10";}
else if(val0 == "nov") {val0 = "11";}
else if (val0 == "dec") {val0 = "12";}
string date = String.Format("{0:dd/MM/yy}","21/11/1992");
int QuaID = 0;
for (int incr = 2; incr <= 7; incr++)
{
string Sql_QuaID = "Select QUA_ID from QUART WHERE QUA_NOM = @QuaNom";
SqlCommand cmd_QuaID = new SqlCommand();
if (incr == 2) { cmd_QuaID.Parameters.Add("@QuaNom", SqlDbType.NVarChar).Value = val2; header = header2; }
else if (incr == 3) { cmd_QuaID.Parameters.Add("@QuaNom", SqlDbType.NVarChar).Value = val3; header = header3; }
else if (incr == 4) { cmd_QuaID.Parameters.Add("@QuaNom", SqlDbType.NVarChar).Value = val4; header = header4; }
else if (incr == 5) { cmd_QuaID.Parameters.Add("@QuaNom", SqlDbType.NVarChar).Value = val5; header = header5; }
else if (incr == 6) { cmd_QuaID.Parameters.Add("@QuaNom", SqlDbType.NVarChar).Value = val6; header = header6; }
else if (incr == 7) { cmd_QuaID.Parameters.Add("@QuaNom", SqlDbType.NVarChar).Value = val7; header = header7; }
cmd_QuaID.Connection = Connection;
cmd_QuaID.CommandText = Sql_QuaID;
Connection.Open();
QuaID = (Int32)cmd_QuaID.ExecuteScalar();
Connection.Close();
cmd_QuaID.Dispose();
RotID++;
dbOperations.Add("INSERT INTO ROTATION (ROT_ID, ROT_DATROTATION, ROT_PERIODE, ROT_QUAID, ROT_ANNEE, ROT_MOIS, ROT_JOUR) VALUES (" + (RotID) + "," + date + ",'" + header + "'," + QuaID + "," + TXTB_annee_shift.Text + "," + val0 + "," + val1 + ")");
}
}
}
Connection.Open();
SqlTransaction transaction = Connection.BeginTransaction();
foreach (string commandString in dbOperations)
{
SqlCommand cmd = new SqlCommand(commandString, Connection, transaction);
cmd.ExecuteNonQuery();
}
transaction.Commit();
} |
Partager