public FormAdmin(DBconnector.DBconnector connector, bool admin) { InitializeComponent(); if (!admin) { usersToolStripMenuItem.Enabled = false; usersToolStripMenuItem.Visible = false; productsToolStripMenuItem.Enabled = false; productsToolStripMenuItem.Visible = false; scheduleToolStripMenuItem.Enabled = false; scheduleToolStripMenuItem.Visible = false; this.Text = "General User"; } else { this.Text = "Admin User"; } this.connector = connector; DataTable dt = new DataTable(); string result = this.connector.GetRework(dt); if (result != "") { MessageBox.Show("Could not get reworks"); } else { foreach (DataRow row in dt.Rows) { comboBoxRework.Items.Add(row["Reason"].ToString()); } if (comboBoxRework.Items.Count != 0) { comboBoxRework.SelectedIndex = 0; } } dt.Clear(); result = this.connector.GetReject(dt); if (result != "") { MessageBox.Show("Could not get rejects"); } else { foreach (DataRow row in dt.Rows) { comboBoxReject.Items.Add(row["Reason"].ToString()); } if (comboBoxReject.Items.Count != 0) { comboBoxReject.SelectedIndex = 0; } } }
static void Main(string[] args) { string connectionString = ""; bool ok = true; try { connectionString = System.IO.File.ReadAllText("connection.txt"); connectionString = connectionString.Replace(@"\\", @"\"); } catch (Exception ex) { Console.WriteLine(ex.Message); ok = false; } if (ok) { List<Record> listRec = new List<Record>(); Record rec = new Record(); int element = 0; XmlTextReader reader; try { reader = new XmlTextReader("testData.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "record") { rec = new Record(); rec.error = ""; } else if (reader.Name == "workArea") { element = 1; } else if (reader.Name == "part") { element = 2; } else if (reader.Name == "line") { element = 3; } else if (reader.Name == "state") { element = 4; } else if (reader.Name == "error") { element = 5; } else if (reader.Name == "timestamp") { element = 6; } break; case XmlNodeType.Text: switch (element) { case 1: rec.workArea = reader.Value; break; case 2: rec.part = reader.Value; break; case 3: rec.line = reader.Value; break; case 4: rec.state = reader.Value; break; case 5: rec.error = reader.Value; break; case 6: rec.timestamp = reader.Value; break; } break; case XmlNodeType.EndElement: element = 0; if (reader.Name == "record") { listRec.Add(rec); } break; } } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); ok = false; } if (ok) { DBconnector.DBconnector connector = null; try { connector = new DBconnector.DBconnector(connectionString); } catch (Exception ex) { Console.WriteLine(ex.Message); ok = false; } if (ok) { string result = ""; int insertion = 0; int failed = 0; for (int counter = 0; counter < listRec.Count; counter++) { result = connector.InsertRecord(listRec[counter], out insertion); if (result != "" || insertion != 0) { if (result != "") { Console.WriteLine(result + "\nFor the element " + listRec[counter].workArea + " " + listRec[counter].part + " " + listRec[counter].line + " " + listRec[counter].state + " " + listRec[counter].error + " " + listRec[counter].timestamp); } if (insertion != 0) { Console.WriteLine("Insertion Failed" + "\nFor the element " + listRec[counter].workArea + " " + listRec[counter].part + " " + listRec[counter].line + " " + listRec[counter].state + " " + listRec[counter].error + " " + listRec[counter].timestamp); } failed++; } } if (failed != 0) { Console.WriteLine(failed.ToString() + " parts failed to insert into the database"); } else { Console.WriteLine("All " + listRec.Count + " parts where inserted successfully"); } } } } }