private void items_load() { Company_name.Items.Clear(); try { con.open(); command = new SqlCommand("Select [Company_Name] from Company", con.conn); // command.Parameters.AddWithValue("@zip", "india"); // int result = command.ExecuteNonQuery(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader[0].ToString().Trim() != "") { Company_name.Items.Add(reader[0].ToString()); } } } con.close(); } catch (Exception ex) { string error = ex.ToString(); Msg_E = new MsgBox_Error(); Msg_E.ShowMsg("هنالك مشكلة بالاتصال مع الخادم الرئيسي للمديرية" + "\n" + "نوع الخطأ" + "\n" + error.Substring(0, 30), "خطأ"); con.close(); } }
//close connection public void close() { try { conn.Close(); } catch (Exception ex) { string error = ex.ToString(); Msg = new MsgBox_Error(); Msg.ShowMsg("هنالك مشكلة بالاتصال مع الخادم الرئيسي للمديرية" + "\n" + "نوع الخطأ" + "\n" + error.Substring(0, 30), "خطأ"); // MessageBox.Show("هنالك مشكلة بالاتصال مع الخادم الرئيسي للمديرية" + "\n" + "نوع الخطأ" + "\n" + error.Substring(0, 20), "فشل الاتصال", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading); } }
private void Button8_Click(object sender, EventArgs e) { try { con.open(); if (comboBox1.Text == "" || textBox5.Text == "" || comboBox3.Text == "") { // MessageBox.Show("هنالك حقول قارغة", "....", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading); Msg_El = new Form1(); Msg_El.Show("هنالك حقول فارغة يجب تعبئة جميع الحقول"); con.close(); return; } Printer_Type = comboBox1.Text; Print_Name = comboBox2.Text; Company_Name = textBox5.Text; Usages = comboBox3.Text; Note = textBox2.Text; Colored = 0; Scan = 0; Ethernet = 0; Copy = 0; print = 0; if (Colored_Check.Checked == true) { Colored = 1; } if (Scan_Check.Checked == true) { Scan = 1; } if (Ethernet_Check.Checked == true) { Ethernet = 1; } if (Copy_Check.Checked == true) { Copy = 1; } if (Print_Check.Checked == true) { print = 1; } //Update Printer table SqlStatement = "update printers set [Print_Type] = @Print_Type, [Company_name] = @Company_name, [Usages] = @Usages,[Note] = @Note ,[Scan] = @Scan, [Colored] = @Colored, [Ethernet] = @Ethernet, [Copy]= @Copy, [Print] = @Print where [Print_Name] = @Printer_Name"; command = new SqlCommand(SqlStatement, con.conn); command.Parameters.AddWithValue("@Printer_Name", Print_Name); command.Parameters.AddWithValue("@Print_Type", Printer_Type); command.Parameters.AddWithValue("@Company_name", Company_Name); command.Parameters.AddWithValue("@Usages", Usages); command.Parameters.AddWithValue("@Note", Note); command.Parameters.AddWithValue("@Scan", Scan); command.Parameters.AddWithValue("@Colored", Colored); command.Parameters.AddWithValue("@Ethernet", Ethernet); command.Parameters.AddWithValue("@Copy", Copy); command.Parameters.AddWithValue("@Print", print); sqladapter.InsertCommand = command; sqladapter.InsertCommand.ExecuteNonQuery(); command.Dispose(); //Delete Old Items from Inks_Store tables SqlStatement = "Delete from Inks_Store where [Printer_Name]='" + Print_Name + "'"; command = new SqlCommand(SqlStatement, con.conn); sqladapter.InsertCommand = command; sqladapter.InsertCommand.ExecuteNonQuery(); command.Dispose(); //Add New Items to inks table foreach (DataGridViewRow g1 in dataGridView1.Rows) { if (!string.IsNullOrEmpty(g1.Cells[0].Value as string)) { command = new SqlCommand("insert into Inks_Store([Printer_Name],[Ink_Number],[Color]) values ('" + comboBox2.Text + "','" + g1.Cells[0].Value + "',N'" + g1.Cells[1].Value + "')", con.conn); command.ExecuteNonQuery(); } } con.close(); Msg_Info = new MsgBox_Info(); Msg_Info.ShowMsg("تمت عملية الحفظ بنجاح", "تم"); } catch { Msg_E = new MsgBox_Error(); Msg_E.ShowMsg("حدث خطأ أثناء عملية التحديث للبيانات", "خطأ"); con.close(); } }
private void Button1_Click_1(object sender, EventArgs e) { Form1 Msg; try { if (comboBox1.Text == "" || textBox1.Text == "" || textBox5.Text == "" || comboBox3.Text == "") { // MessageBox.Show(Cursor.Position.X.ToString()); //Msg_Info.ShowMsg("هنالك حقول قارغة ,يجب تعبئة كافة الحقول", "حقول فارغة"); Msg = new Form1(); Msg.Show("هنالك حقول قارغة ,يجب تعبئة كافة الحقول"); return; } con = new Connection(); con.open(); Exist = false; // TO Check If Value exists SqlStatement = "select [Print_Name] from Printers"; command = new SqlCommand(SqlStatement, con.conn); Read = command.ExecuteReader(); while (Read.Read()) { if (Read[0].ToString().Trim().ToLower() == textBox1.Text.Trim().ToLower()) { Exist = true; Msg_Info = new MsgBox_Info(); Msg_Info.ShowMsg("....أسم الجهاز موجود بالفعل ", "أسم الجهاز مدخل سابقاً"); command.Dispose(); con.close(); return; } } Printer_Type = comboBox1.Text; Printer_Name = textBox1.Text; Company_Name = textBox5.Text; Usages = comboBox3.Text; Note = textBox2.Text; Colored = 0; Scan = 0; Ethernet = 0; Copy = 0; print = 0; if (Colored_Check.Checked == true) { Colored = 1; } if (Scan_Check.Checked == true) { Scan = 1; } if (Ethernet_Check.Checked == true) { Ethernet = 1; } if (Copy_Check.Checked == true) { Copy = 1; } if (Print_Check.Checked == true) { print = 1; } SqlStatement = "insert into printers([Print_Type],[Print_Name],[Company_name],[Usages],[Scan],[Colored],[Ethernet],[Copy],[Print],[Note]) values (N'" + Printer_Type + "','" + Printer_Name + "','" + Company_Name + "','" + Usages + "','" + Scan + "','" + Colored + "','" + Ethernet + "','" + Copy + "','" + print + "',N'" + Note + "')"; command = new SqlCommand(SqlStatement, con.conn); sqladapter.InsertCommand = command; sqladapter.InsertCommand.ExecuteNonQuery(); command.Dispose(); foreach (DataGridViewRow g1 in dataGridView1.Rows) { if (!string.IsNullOrEmpty(g1.Cells[0].Value as string)) { command = new SqlCommand("insert into Inks_Store([Printer_Name],[Ink_Number],[Color]) values ('" + textBox1.Text + "','" + g1.Cells[0].Value + "',N'" + g1.Cells[1].Value + "')", con.conn); command.ExecuteNonQuery(); } } con.close(); Msg_Info = new MsgBox_Info(); Msg_Info.ShowMsg("تمت عملية الحفظ بنجاح", "تم"); } catch { Msg_Er = new MsgBox_Error(); Msg_Er.ShowMsg("حدث خطأ أثناء تنقيذ عملية الادخال", "خطأ"); con.close(); } }
private void Button3_Click(object sender, EventArgs e) { try { if (this.Company_name.Text == "" || this.Phone.Text == "" || this.Location.Text == "") { // MessageBox.Show("هنالك حقول قارغة", "....", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading); Msg_El = new Form1(); Msg_El.Show("هنالك حقول قارغة يجب تعبئة كافة الحقول"); return; } con.open(); if (Selected_value == true) { Update_Values(); } else { int Inks_value = 0; int Printers_value = 0; int Hardware_value = 0; if (Inks.Checked == true) { Inks_value = 1; } if (Printers.Checked == true) { Printers_value = 1; } if (Hardware.Checked == true) { Hardware_value = 1; } //Insert new Items to Companies tables SqlStatement = "insert into Company([Company_Name],[Phone],[Location],[Ink_Deal],[Printer_Deal],[Hardware_Deal]) values (N'" + this.Company_name.Text + "','" + this.Phone.Text + "',N'" + this.Location.Text + "','" + Inks_value + "','" + Printers_value + "','" + Hardware_value + "')"; command = new SqlCommand(SqlStatement, con.conn); sqladapter = new SqlDataAdapter(); sqladapter.InsertCommand = command; sqladapter.InsertCommand.ExecuteNonQuery(); command.Dispose(); Msg_Info = new MsgBox_Info(); Msg_Info.ShowMsg("تمت عملية الحفظ بنجاح", "تم"); } con.close(); items_load(); } catch { Msg_E = new MsgBox_Error(); Msg_E.ShowMsg("حدث خطأ أثناء عملية التحديث للبيانات", "خطأ"); con.close(); } }