public static List <Clamp> SelectClampValuesRN(string query, string param1, string param2) { List <Clamp> result = new List <Clamp>(); try { using (MySqlConnection conn = new MySqlConnection(con)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.AddWithValue("?param1", param1); cmd.Parameters.AddWithValue("?param2", param2); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Clamp clamp = new Clamp() { Rn = reader.GetString("rn") }; result.Add(clamp); } } } } } catch (Exception ex) { string newfolder = direktorijum + "\\Logs"; if (!Directory.Exists(newfolder)) { Directory.CreateDirectory(newfolder); } newfolder += "\\log9" + DateTime.Now.ToString("dd_MM_yyyy hh_mm_ss") + ".txt"; StreamWriter sw = new StreamWriter(newfolder); sw.Write(ex.ToString()); sw.Close(); } return(result); }
public BasicForm() { InitializeComponent(); //butStat.Hide(); //save = @"\\10.0.140.11\share\NCPR"; save = ConfigurationManager.AppSettings["DirectoryFilepath"]; cbClampType.Items.AddRange(clamps); ff = new FillInForm(); clamp = new Clamp(); basicData = new Clamp(); errorClamp = new Clamp(); filepath = ""; bgWorker.DoWork += BgWorker_DoWork; bgWorker.ProgressChanged += BgWorker_ProgressChanged; bgWorker.RunWorkerCompleted += BgWorker_RunWorkerCompleted; }
public static Clamp ReturnClamp() { Clamp clamp = new Clamp(); try { clamp = ClampConnectionClass.SelectClamp(Program.clampSelectQuery); } catch (Exception ex) { string newfolder = direktorijum + "\\Logs"; if (!Directory.Exists(newfolder)) { Directory.CreateDirectory(newfolder); } newfolder += "\\log16" + DateTime.Now.ToString("dd_MM_yyyy hh_mm_ss") + ".txt"; StreamWriter sw = new StreamWriter(newfolder); sw.Write(ex.ToString()); sw.Close(); } return(clamp); }
public static bool ClampExists(string query, Clamp clamp) { bool result = false; try { using (MySqlConnection conn = new MySqlConnection(con)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.AddWithValue("?param1", clamp.Serialnum); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { result = true; } } } } } catch (Exception ex) { string newfolder = direktorijum + "\\Logs"; if (!Directory.Exists(newfolder)) { Directory.CreateDirectory(newfolder); } newfolder += "\\log10" + DateTime.Now.ToString("dd_MM_yyyy hh_mm_ss") + ".txt"; StreamWriter sw = new StreamWriter(newfolder); sw.Write(ex.ToString()); sw.Close(); result = false; } return(result); }
private void butSerialUpdate_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(textBox6.Text) && !String.IsNullOrEmpty(textBox7.Text)) { status.Text = "Please wait..."; status.ForeColor = Color.Red; status.Visible = true; Clamp clamp = new Clamp() { Rado = textBox7.Text, Serialnum = textBox6.Text }; bool result = ClampOperations.UpdateClampBarcode(clamp); if (result) { MessageBox.Show("Success"); textBox6.Clear(); textBox7.Clear(); status.ForeColor = Color.Green; status.Text = "Done"; } else { MessageBox.Show("Could not update your barcode"); status.ForeColor = Color.Red; status.Text = "Error"; } } else { MessageBox.Show("Please fill in all data"); } }
public static Clamp SelectClamp(string query) { Clamp clamp = new Clamp(); try { using (MySqlConnection conn = new MySqlConnection(con)) { conn.Open(); using (MySqlCommand command = new MySqlCommand(query, conn)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { clamp.Serialnum = reader.GetString("serialnum"); clamp.Rado = reader.GetString("rado"); clamp.Rn = reader.GetString("rn"); } } } } } catch (Exception ex) { string newfolder = direktorijum + "\\Logs"; if (!Directory.Exists(newfolder)) { Directory.CreateDirectory(newfolder); } newfolder += "\\log4" + DateTime.Now.ToString("dd_MM_yyyy hh_mm_ss") + ".txt"; StreamWriter sw = new StreamWriter(newfolder); sw.Write(ex.ToString()); sw.Close(); } return(clamp); }
public static bool UpdateClampBarCode(string query, Clamp clamp) { bool executed = false; try { using (MySqlConnection conn = new MySqlConnection(con)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.AddWithValue("?param1", clamp.Rado); cmd.Parameters.AddWithValue("?param2", clamp.Serialnum); cmd.ExecuteNonQuery(); executed = true; Debug.Write(query); } } } catch (Exception ex) { string newfolder = direktorijum + "\\Logs"; if (!Directory.Exists(newfolder)) { Directory.CreateDirectory(newfolder); } newfolder += "\\log5" + DateTime.Now.ToString("dd_MM_yyyy hh_mm_ss") + ".txt"; StreamWriter sw = new StreamWriter(newfolder); sw.Write(ex.ToString()); sw.Close(); //Debug.Write(ex.ToString()); executed = false; } return(executed); }
private static void PinchClamp(Microsoft.Office.Interop.Excel._Worksheet oSheet, Clamp clamp) { foreach (Excel.Shape sh in oSheet.Shapes) { if (sh.Name != "Picture 2") { sh.Delete(); } else if (sh.Name != "Picture 1") { sh.Delete(); } } oSheet.Shapes.AddPicture(clamp.Barcode, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, 500, 172, 131, 40); /*Image oImage = Image.FromFile(clamp.Barcode); * System.Windows.Forms.Clipboard.SetDataObject(oImage, true); * * Excel.Range oRange = (Excel.Range)oSheet.Cells[12, 5]; * oSheet.Paste(oRange, oImage);*/ //oSheet.Shapes.AddPicture(clamp.Barcode, MsoTriState.msoTrue, MsoTriState.msoTrue, 5, 12, 131, 40); oSheet.Cells[9, 3] = clamp.Controldate; oSheet.Cells[10, 3] = clamp.Controldate; oSheet.Cells[9, 7] = clamp.Rn; //if (clamp.Clamptype.Contains("WH1 - 15V") || clamp.Clamptype.Contains("WH2 - 15V")) oSheet.Cells[14, 3] = "15V"; //else oSheet.Cells[14, 2] = "24V"; oSheet.Cells[12, 2] = clamp.Serialnum; oSheet.Cells[12, 3] = clamp.Rado; //if (clamp.Rfcablerror.Contains("-")) //{ // oSheet.Cells[19, 3] = clamp.Rfcable; // oSheet.Cells[19, 4] = "-"; // oSheet.Cells[19, 5] = "-"; //} //else //{ // oSheet.Cells[19, 3] = "-"; // oSheet.Cells[19, 4] = clamp.Rfcable; // oSheet.Cells[19, 5] = clamp.Rfcablerror; //} if (clamp.Solenoidcablerror.Contains("-")) { oSheet.Cells[19, 3] = clamp.Solenoidcable; oSheet.Cells[19, 4] = "-"; oSheet.Cells[19, 5] = "-"; } else { oSheet.Cells[19, 3] = "-"; oSheet.Cells[19, 4] = clamp.Solenoidcable; oSheet.Cells[19, 5] = clamp.Solenoidcablerror; } //if (clamp.Smberror.Contains("-")) //{ // oSheet.Cells[21, 3] = clamp.Smb; // oSheet.Cells[21, 4] = "-"; // oSheet.Cells[21, 5] = "-"; //} //else //{ // oSheet.Cells[21, 3] = "-"; // oSheet.Cells[21, 4] = clamp.Smb; // oSheet.Cells[21, 5] = clamp.Smberror; //} if (clamp.Armaturerror.Contains("-")) { oSheet.Cells[20, 3] = clamp.Armature; oSheet.Cells[20, 4] = "-"; oSheet.Cells[20, 5] = "-"; } else { oSheet.Cells[20, 3] = "-"; oSheet.Cells[20, 4] = clamp.Armature; oSheet.Cells[20, 5] = clamp.Armaturerror; } if (clamp.Edgeserror.Contains("-")) { oSheet.Cells[21, 3] = clamp.Edges; oSheet.Cells[21, 4] = "-"; oSheet.Cells[21, 5] = "-"; } else { oSheet.Cells[21, 3] = "-"; oSheet.Cells[21, 4] = clamp.Edges; oSheet.Cells[21, 5] = clamp.Edgeserror; } if (clamp.Paralelityerror.Contains("-")) { oSheet.Cells[25, 3] = clamp.Paralelity; oSheet.Cells[25, 4] = "-"; oSheet.Cells[25, 5] = clamp.Paralelityerror; } else { oSheet.Cells[25, 3] = "-"; oSheet.Cells[25, 4] = clamp.Paralelity; oSheet.Cells[25, 5] = clamp.Paralelityerror; } if (clamp.Distancerror.Contains("-")) { oSheet.Cells[26, 3] = clamp.Distance; oSheet.Cells[26, 4] = "-"; oSheet.Cells[26, 5] = clamp.Distancerror; } else { oSheet.Cells[26, 3] = "-"; oSheet.Cells[26, 4] = clamp.Distance; oSheet.Cells[26, 5] = clamp.Distancerror; } //oSheet.Cells[29, 3] = clamp.Rflenght; //oSheet.Cells[29, 5] = clamp.Rflenghterror; oSheet.Cells[27, 3] = clamp.Solenoidlenght; oSheet.Cells[27, 5] = clamp.Solenoidlenghterror; oSheet.Cells[28, 3] = clamp.Electrodes; oSheet.Cells[28, 5] = clamp.Electrodeserror; oSheet.Cells[32, 3] = clamp.Smallresistance; oSheet.Cells[32, 5] = clamp.Smallresistancerror; oSheet.Cells[33, 3] = clamp.Bigresistance; oSheet.Cells[33, 5] = clamp.Bigresistancerror; oSheet.Cells[34, 3] = clamp.Shortcircuit; oSheet.Cells[34, 5] = clamp.Shortcircuiterror; /*oSheet.Cells[41, 2] = clamp.Emptythick; * oSheet.Cells[41, 5] = clamp.Emptythickerror; * * oSheet.Cells[42, 2] = clamp.Fullthick; * oSheet.Cells[42, 5] = clamp.Fullthickerror; * * oSheet.Cells[43, 2] = clamp.Emptythin; * oSheet.Cells[43, 5] = clamp.Emptythinerror; * * oSheet.Cells[44, 2] = clamp.Fullthin; * oSheet.Cells[44, 5] = clamp.Fullthinerror;*/ }
public static bool crateFinalControl(string save, Clamp clamp) { bool open = false; Microsoft.Office.Interop.Excel.Application oXL = null; Microsoft.Office.Interop.Excel._Workbook oWB = null; Microsoft.Office.Interop.Excel._Worksheet oSheet = null; //Microsoft.Office.Interop.Excel.Range oRng; object misvalue = System.Reflection.Missing.Value; try { //Start Excel and get Application object. oXL = new Microsoft.Office.Interop.Excel.Application(); //oXL.Visible = true; // oWB = (Excel.Workbook)(oXL.Workbooks._Open(@"C:\Users\AleksandraTos\Documents\Visual Studio 2008\Projects\Control Generator\bin\Debug\final control.xlsx", Missing.Value, //Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, //Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); oWB = (Excel.Workbook)(oXL.Workbooks._Open(save, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); //Get a new workbook. //oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add("")); oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet; if (!clamp.Clamptype.Contains("PC")) { RegularClamp(oSheet, clamp); } else { PinchClamp(oSheet, clamp); } oXL.Visible = false; oXL.UserControl = false; oWB.SaveAs(save, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //oWB.Close(true, open, Missing.Value); open = true; oWB.Close(true, Missing.Value, Missing.Value); oXL.Quit(); Marshal.ReleaseComObject(oSheet); Marshal.ReleaseComObject(oWB); Marshal.ReleaseComObject(oXL); } catch (Exception ex) { string newfolder = direktorijum + "\\Logs"; if (!Directory.Exists(newfolder)) { Directory.CreateDirectory(newfolder); } newfolder += "\\log21" + DateTime.Now.ToString("dd_MM_yyyy hh_mm_ss") + ".txt"; StreamWriter sw = new StreamWriter(newfolder); sw.Write(ex.ToString()); sw.Close(); //MessageBox.Show("Something went wrong during the creation of the control file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //if (!Directory.Exists(direktorijum + @"\Log Files")) Directory.CreateDirectory(direktorijum + @"\Log Files"); //StreamWriter sw = new StreamWriter(direktorijum + "\\Log Files\\Log" + DateTime.Now.ToString("dd-MM-yyyy -- HH-mm-ss") + ".txt"); //sw.Write(ex); //sw.Close(); open = false; } finally { } return(open); }
public static bool CreateClamp(string query, Clamp clamp) { bool executed = false; try { using (MySqlConnection conn = new MySqlConnection(con)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.AddWithValue("?param1", clamp.Clamptype); cmd.Parameters.AddWithValue("?param2", clamp.Serialnum); cmd.Parameters.AddWithValue("?param3", clamp.Rado); cmd.Parameters.AddWithValue("?param4", clamp.Rn); cmd.Parameters.AddWithValue("?param5", clamp.Controldate); cmd.Parameters.AddWithValue("?param6", clamp.Barcode); cmd.Parameters.AddWithValue("?param7", clamp.Rfcable); cmd.Parameters.AddWithValue("?param8", clamp.Rfcablerror); cmd.Parameters.AddWithValue("?param9", clamp.Solenoidcable); cmd.Parameters.AddWithValue("?param10", clamp.Solenoidcablerror); cmd.Parameters.AddWithValue("?param11", clamp.Smb); cmd.Parameters.AddWithValue("?param12", clamp.Smberror); cmd.Parameters.AddWithValue("?param13", clamp.Armature); cmd.Parameters.AddWithValue("?param14", clamp.Armaturerror); cmd.Parameters.AddWithValue("?param15", clamp.Edges); cmd.Parameters.AddWithValue("?param16", clamp.Edgeserror); cmd.Parameters.AddWithValue("?param17", clamp.Paralelity); cmd.Parameters.AddWithValue("?param18", clamp.Paralelityerror); cmd.Parameters.AddWithValue("?param19", clamp.Distance); cmd.Parameters.AddWithValue("?param20", clamp.Distancerror); cmd.Parameters.AddWithValue("?param21", clamp.Rflenght); cmd.Parameters.AddWithValue("?param22", clamp.Rflenghterror); cmd.Parameters.AddWithValue("?param23", clamp.Solenoidlenght); cmd.Parameters.AddWithValue("?param24", clamp.Solenoidlenghterror); cmd.Parameters.AddWithValue("?param25", clamp.Electrodes); cmd.Parameters.AddWithValue("?param26", clamp.Electrodeserror); cmd.Parameters.AddWithValue("?param27", clamp.Bigresistance); cmd.Parameters.AddWithValue("?param28", clamp.Bigresistancerror); cmd.Parameters.AddWithValue("?param29", clamp.Smallresistance); cmd.Parameters.AddWithValue("?param30", clamp.Smallresistancerror); cmd.Parameters.AddWithValue("?param31", clamp.Shortcircuit); cmd.Parameters.AddWithValue("?param32", clamp.Shortcircuiterror); cmd.Parameters.AddWithValue("?param33", clamp.Emptythick); cmd.Parameters.AddWithValue("?param34", clamp.Emptythickerror); cmd.Parameters.AddWithValue("?param35", clamp.Fullthick); cmd.Parameters.AddWithValue("?param36", clamp.Fullthickerror); cmd.Parameters.AddWithValue("?param37", clamp.Emptythin); cmd.Parameters.AddWithValue("?param38", clamp.Emptythinerror); cmd.Parameters.AddWithValue("?param39", clamp.Fullthin); cmd.Parameters.AddWithValue("?param40", clamp.Fullthinerror); cmd.ExecuteNonQuery(); executed = true; //Debug.Write(query); } } } catch (Exception ex) { string newfolder = direktorijum + "\\Logs"; if (!Directory.Exists(newfolder)) { Directory.CreateDirectory(newfolder); } newfolder += "\\log13" + DateTime.Now.ToString("dd_MM_yyyy hh_mm_ss") + ".txt"; StreamWriter sw = new StreamWriter(newfolder); sw.Write(ex.ToString()); sw.Close(); //Debug.Write(ex.ToString()); executed = false; } return(executed); }
public Clamp NewUpdate(Clamp clamp) //TODO: uzmi u obzir da svako polje treba da ti bude popunjeno, nemoj da zaboravis da ispitas to { if (checkBox1.Enabled) { //Debug.Write(clamp); if (checkBox1.Checked) { clamp.Rfcable = "OK"; clamp.Rfcablerror = "-"; } else if (checkBox6.Checked) { clamp.Rfcable = "NOT OK"; clamp.Rfcablerror = richTextBox1.Text; } else { clamp.Clampimputerror += " RF cable"; } } else { clamp.Rfcable = "-"; clamp.Rfcablerror = "-"; } if (checkBox2.Checked) { clamp.Solenoidcable = "OK"; clamp.Solenoidcablerror = "-"; } else if (checkBox7.Checked) { clamp.Solenoidcable = "NOT OK"; clamp.Solenoidcablerror = richTextBox2.Text; } else { clamp.Clampimputerror += " solenoid cable"; } if (checkBox3.Enabled) { if (checkBox3.Checked) { clamp.Smb = "OK"; clamp.Smberror = "-"; } else if (checkBox8.Checked) { clamp.Smb = "NOT OK"; clamp.Smberror = richTextBox6.Text; } else { clamp.Clampimputerror += " SMB"; } } else { clamp.Smb = "-"; clamp.Smberror = "-"; } if (checkBox4.Checked) { clamp.Armature = "OK"; clamp.Armaturerror = "-"; } else if (checkBox9.Checked) { clamp.Armature = "NOT OK"; clamp.Armaturerror = richTextBox3.Text; } else { clamp.Clampimputerror += " armature"; } if (checkBox5.Checked) { clamp.Edges = "OK"; clamp.Edgeserror = "-"; } else if (checkBox10.Checked) { clamp.Edges = "NOT OK"; clamp.Edgeserror = richTextBox4.Text; } else { clamp.Clampimputerror += " edges"; } if (checkBox20.Enabled) { if (checkBox20.Checked) //if (!clamp.Clamtype = "PC") { clamp.Paralelity = "OK"; clamp.Paralelityerror = "-"; } else if (checkBox19.Checked) { clamp.Paralelity = "NOT OK"; clamp.Paralelityerror = richTextBox11.Text; } else { clamp.Clampimputerror += " paralelity check"; } } else { if (checkBox28.Checked) //if (clamp.Clamtype = "PC") { clamp.Paralelity = "OK"; clamp.Paralelityerror = "-"; } else if (checkBox27.Checked) { clamp.Paralelity = "NOT OK"; clamp.Paralelityerror = richTextBox11.Text; } else { clamp.Clampimputerror += " paralelity check"; } } if (checkBox21.Enabled) { if (checkBox21.Checked) //if (!clamp.Clamtype = "PC") { clamp.Distance = "OK"; clamp.Distancerror = "-"; } else if (checkBox23.Checked) { clamp.Distance = "NOT OK"; clamp.Distancerror = richTextBox12.Text; } else { clamp.Clampimputerror += " distance check"; } } else { if (checkBox26.Checked) //if (clamp.Clamtype = "PC") { clamp.Distance = "OK"; clamp.Distancerror = "-"; } else if (checkBox25.Checked) { clamp.Distance = "NOT OK"; clamp.Distancerror = richTextBox12.Text; } else { clamp.Clampimputerror += " distance check"; } } if (checkBox22.Enabled) { if (checkBox22.Checked) { clamp.Rflenght = "OK"; clamp.Rflenghterror = "-"; } else if (checkBox24.Checked) { clamp.Rflenght = "NOT OK"; clamp.Rflenghterror = richTextBox13.Text; } else { clamp.Clampimputerror += " RF lenght"; } } else { clamp.Rflenght = "-"; clamp.Rflenghterror = "-"; } clamp.Solenoidlenght = richTextBox9.Text; clamp.Solenoidlenghterror = richTextBox14.Text; if (String.IsNullOrEmpty(richTextBox10.Text)) { clamp.Electrodes = richTextBox10.Text; clamp.Electrodeserror = richTextBox15.Text; } else { clamp.Electrodes = richTextBox16.Text; clamp.Electrodeserror = richTextBox8.Text; } if (richTextBox24.Enabled) { if (!String.IsNullOrEmpty(richTextBox24.Text)) { clamp.Bigresistance = richTextBox24.Text; //Debug.Write(richTextBox24.Text + "bleh "); clamp.Bigresistancerror = richTextBox19.Text; clamp.Smallresistance = richTextBox23.Text; //Debug.Write(richTextBox23.Text + "bleh"); clamp.Smallresistancerror = richTextBox18.Text; } else { clamp.Clampimputerror += " resistance"; } } if (richTextBox23.Enabled) { if (!String.IsNullOrEmpty(richTextBox23.Text)) { clamp.Bigresistance = richTextBox24.Text; //Debug.Write(richTextBox24.Text + "bleh "); clamp.Bigresistancerror = richTextBox19.Text; clamp.Smallresistance = richTextBox23.Text; //Debug.Write(richTextBox23.Text + "bleh"); clamp.Smallresistancerror = richTextBox18.Text; } else { clamp.Clampimputerror += " resistance"; } } clamp.Shortcircuit = richTextBox22.Text; clamp.Shortcircuiterror = richTextBox17.Text; if (tabPage4.Enabled) { if (checkBox11.Checked) { clamp.Emptythick = "OK"; clamp.Emptythickerror = "-"; } else if (checkBox15.Checked) { clamp.Emptythick = "NOT OK"; clamp.Emptythickerror = richTextBox23.Text; } else { clamp.Clampimputerror += " empty thick"; } if (checkBox12.Checked) { clamp.Fullthick = "OK"; clamp.Fullthickerror = "-"; } else if (checkBox16.Checked) { clamp.Fullthick = "NOT OK"; clamp.Fullthickerror = richTextBox29.Text; } else { clamp.Clampimputerror += " full thick"; } if (checkBox13.Checked) { clamp.Emptythin = "OK"; clamp.Emptythinerror = "-"; } else if (checkBox17.Checked) { clamp.Emptythin = "NOT OK"; clamp.Emptythinerror = richTextBox28.Text; } else { clamp.Clampimputerror += " empty thin"; } if (checkBox14.Checked) { clamp.Fullthin = "OK"; clamp.Fullthinerror = "-"; } else if (checkBox18.Checked) { clamp.Fullthin = "NOT OK"; clamp.Fullthinerror = richTextBox27.Text; } else { clamp.Clampimputerror += " full thin"; } } else { clamp.Emptythick = "-"; clamp.Emptythickerror = "-"; clamp.Fullthick = "-"; clamp.Fullthickerror = "-"; clamp.Emptythin = "-"; clamp.Emptythinerror = "-"; clamp.Fullthin = "-"; clamp.Fullthinerror = "-"; } return(clamp); }