//InSertAllCustomer private int InSertAllCustomer(DataTable tb_customer) { int result = 0; foreach (DataRow datarow in tb_customer.Rows) { if (datarow[0].ToString() != "") { EC_tb_Customer ec_tb_customer = new EC_tb_Customer(); ec_tb_customer.CustomerID = Convert.ToInt32(datarow[0].ToString()); ec_tb_customer.FirstName = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[1].ToString()); ec_tb_customer.LastName = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[2].ToString()); ec_tb_customer.Address1 = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[3].ToString()); ec_tb_customer.Address2 = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[4].ToString()); ec_tb_customer.City = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[5].ToString()); ec_tb_customer.State = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[6].ToString()); ec_tb_customer.Zipcode = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[7].ToString()); ec_tb_customer.Phone = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[8].ToString()); ec_tb_customer.Email = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[9].ToString()); if (bus_tb_customer.InsertCustomer(ec_tb_customer, StaticClass.GeneralClass.flag_database_type_general) == 1) { result++; } } } return(result); }
//muiBtnOK_Click private void muiBtnOK_Click(object sender, RoutedEventArgs e) { if (txbFirstname.Text == "") { tblNotification.Text = FindResource("first_name_null").ToString(); txbFirstname.Focus(); return; } if (txbLastname.Text == "") { tblNotification.Text = FindResource("last_name_null").ToString(); txbLastname.Focus(); return; } else { try { EC_tb_Customer ec_tb_customer = new EC_tb_Customer(); ec_tb_customer.CustomerID = Convert.ToInt32(tblCustomerID.Text.Trim().ToString()); ec_tb_customer.FirstName = StaticClass.GeneralClass.HandlingSpecialCharacter(txbFirstname.Text.Trim().ToString()); ec_tb_customer.LastName = StaticClass.GeneralClass.HandlingSpecialCharacter(txbLastname.Text.Trim().ToString()); ec_tb_customer.Address1 = StaticClass.GeneralClass.HandlingSpecialCharacter(txbAddress1.Text.Trim().ToString()); ec_tb_customer.Address2 = StaticClass.GeneralClass.HandlingSpecialCharacter(txbAddress2.Text.Trim().ToString()); ec_tb_customer.City = StaticClass.GeneralClass.HandlingSpecialCharacter(txbCity.Text.Trim().ToString()); ec_tb_customer.State = StaticClass.GeneralClass.HandlingSpecialCharacter(txbState.Text.Trim().ToString()); ec_tb_customer.Zipcode = StaticClass.GeneralClass.HandlingSpecialCharacter(txbZipcode.Text.Trim().ToString()); ec_tb_customer.Phone = StaticClass.GeneralClass.HandlingSpecialCharacter(txbPhone.Text.Trim().ToString()); ec_tb_customer.Email = StaticClass.GeneralClass.HandlingSpecialCharacter(txbEmail.Text.Trim().ToString()); if (bus_tb_customer.UpdateCustomer(ec_tb_customer, StaticClass.GeneralClass.flag_database_type_general) == 1) { if (muibtnedit_delegate != null) { StaticClass.GeneralClass.flag_add_edit_delete_customer_general = true; muibtnedit_delegate(); } this.Close(); } else { tblNotification.Text = FindResource("error_updating").ToString(); } } catch (Exception ex) { tblNotification.Text = ex.Message; } } }
//muiBtnOK_Click private void muiBtnOK_Click(object sender, RoutedEventArgs e) { if (StaticClass.GeneralClass.list_ec_tb_customer_general.Count == 0) { tblNotification.Text = FindResource("select_least_customer").ToString(); } else { try { int result = 0; for (int i = 0; i < StaticClass.GeneralClass.list_ec_tb_customer_general.Count; i++) { if (bus_tb_order.GetOrder("WHERE [CustomerID]=" + StaticClass.GeneralClass.list_ec_tb_customer_general[i].CustomerID.ToString()).Rows.Count > 0) { tblNotification.Text = FindResource("customer_id").ToString() + ": " + StaticClass.GeneralClass.list_ec_tb_customer_general[i].CustomerID.ToString() + " " + FindResource("already_uses").ToString(); } else { EC_tb_Customer ec_tb_customer = new EC_tb_Customer(); ec_tb_customer.CustomerID = StaticClass.GeneralClass.list_ec_tb_customer_general[i].CustomerID; if (bus_tb_customer.DeleteCustomer(ec_tb_customer) == 1) { result++; } } } if (result > 0) { if (muibtndelete_delegate != null) { StaticClass.GeneralClass.flag_add_edit_delete_customer_general = true; StaticClass.GeneralClass.list_ec_tb_salesperson_general.Clear(); muibtndelete_delegate(true); this.Close(); } } } catch (Exception ex) { tblNotification.Text = ex.Message; } } }
//insert Customer public int InsertCustomer(EC_tb_Customer ec_tb_cus, bool data_type) { string sql = ""; if (!data_type) { sql = "INSERT INTO [tb_Customer] ([FirstName],[LastName],[Address1],[Address2],[City],[State],[Zipcode],[Phone],[Email]) VALUES('" + ec_tb_cus.FirstName + "','" + ec_tb_cus.LastName + "','" + ec_tb_cus.Address1 + "','" + ec_tb_cus.Address2 + "','" + ec_tb_cus.City + "','" + ec_tb_cus.State + "','" + ec_tb_cus.Zipcode + "','" + ec_tb_cus.Phone + "','" + ec_tb_cus.Email + "')"; } else { sql = "INSERT INTO [tb_Customer] ([FirstName],[LastName],[Address1],[Address2],[City],[State],[Zipcode],[Phone],[Email]) VALUES(N'" + ec_tb_cus.FirstName + "', N'" + ec_tb_cus.LastName + "', N'" + ec_tb_cus.Address1 + "', N'" + ec_tb_cus.Address2 + "', N'" + ec_tb_cus.City + "', N'" + ec_tb_cus.State + "', N'" + ec_tb_cus.Zipcode + "', N'" + ec_tb_cus.Phone + "', N'" + ec_tb_cus.Email + "')"; } return(ConnectionDB.ExecuteNonQuery(sql)); }
//update Customer public int UpdateCustomer(EC_tb_Customer ec_tb_cus, bool data_type) { string sql = ""; if (!data_type) { sql = "UPDATE [tb_Customer] SET [FirstName] = '" + ec_tb_cus.FirstName + "',[LastName] ='" + ec_tb_cus.LastName + "',[Address1] ='" + ec_tb_cus.Address1 + "',[Address2] ='" + ec_tb_cus.Address2 + "',[City] ='" + ec_tb_cus.City + "',[State] ='" + ec_tb_cus.State + "',[Zipcode] ='" + ec_tb_cus.Zipcode + "',[Phone] ='" + ec_tb_cus.Phone + "',[Email] ='" + ec_tb_cus.Email + "' WHERE CustomerID=" + ec_tb_cus.CustomerID; } else { sql = "UPDATE [tb_Customer] SET [FirstName] = N'" + ec_tb_cus.FirstName + "', [LastName] = N'" + ec_tb_cus.LastName + "',[Address1] = N'" + ec_tb_cus.Address1 + "', [Address2] = N'" + ec_tb_cus.Address2 + "', [City] = N'" + ec_tb_cus.City + "', [State] = N'" + ec_tb_cus.State + "',[Zipcode] = N'" + ec_tb_cus.Zipcode + "', [Phone] = N'" + ec_tb_cus.Phone + "', [Email] = N'" + ec_tb_cus.Email + "' WHERE CustomerID=" + ec_tb_cus.CustomerID; } return(ConnectionDB.ExecuteNonQuery(sql)); }
//delete Customer public int DeleteCustomer(EC_tb_Customer ec_tb_cus) { return(sql_tb_cus.DeleteCustomer(ec_tb_cus)); }
//update Customer public int UpdateCustomer(EC_tb_Customer ec_tb_cus, bool data_type) { return(sql_tb_cus.UpdateCustomer(ec_tb_cus, data_type)); }
//insert Customer public int InsertCustomer(EC_tb_Customer ec_tb_cus, bool data_type) { return(sql_tb_cus.InsertCustomer(ec_tb_cus, data_type)); }
private void GetCustomer(int be_limit, int af_limit, string con1, string con2, bool add) { if (thread_content != null && thread_content.ThreadState == ThreadState.Running) { } else { thread_content = new Thread(() => { try { int i = 0; list_ec_tb_customer.Clear(); dt_customer.Clear(); this.Dispatcher.Invoke((Action)(() => { dtgCustomer.Items.Refresh(); })); dt_customer = bus_tb_customer.GetCustomerFollowPaging(be_limit, af_limit, con1, con2, StaticClass.GeneralClass.flag_database_type_general); foreach (DataRow datarow in dt_customer.Rows) { i++; EC_tb_Customer ec_tb_customer = new EC_tb_Customer(); ec_tb_customer.CustomerID = Convert.ToInt32(datarow["CustomerID"].ToString()); ec_tb_customer.FirstName = datarow["FirstName"].ToString(); ec_tb_customer.LastName = datarow["LastName"].ToString(); ec_tb_customer.FullName = ec_tb_customer.FirstName + " " + ec_tb_customer.LastName; ec_tb_customer.Address1 = datarow["Address1"].ToString(); ec_tb_customer.Address2 = datarow["Address2"].ToString(); ec_tb_customer.City = datarow["City"].ToString(); ec_tb_customer.State = datarow["State"].ToString(); ec_tb_customer.Zipcode = datarow["Zipcode"].ToString(); ec_tb_customer.Phone = datarow["Phone"].ToString(); ec_tb_customer.Email = datarow["Email"].ToString(); ec_tb_customer.ImageUrl = @"pack://application:,,,/Resources/select_customer.png"; if (i % 2 != 0) { ec_tb_customer.Background = "AliceBlue"; } list_ec_tb_customer.Add(ec_tb_customer); } this.Dispatcher.Invoke((Action)(() => { dtgCustomer.Items.Refresh(); })); //if is added if (add == true) { this.Dispatcher.Invoke((Action)(() => { dtgCustomer.SelectedIndex = list_ec_tb_customer.Count - 1; dtgCustomer.ScrollIntoView(dtgCustomer.Items.GetItemAt(list_ec_tb_customer.Count - 1)); })); } } catch (Exception ex) { this.Dispatcher.Invoke((Action)(() => { ModernDialog md = new ModernDialog(); md.Title = FindResource("notification").ToString(); md.Content = ex.Message + "!"; md.CloseButton.Content = FindResource("close").ToString(); md.ShowDialog(); })); } }); thread_content.Start(); } }
//delete Customer public int DeleteCustomer(EC_tb_Customer ec_tb_cus) { string sql = "delete from tb_Customer where CustomerID=" + ec_tb_cus.CustomerID; return(ConnectionDB.ExecuteNonQuery(sql)); }
private void GetCustomer(int be_limit, int af_limit, string con1, string con2, bool add, int _row_selected) { if (thread_content != null && thread_content.ThreadState == ThreadState.Running) { } else { thread_content = new Thread(() => { try { list_ec_tb_customer.Clear(); this.Dispatcher.Invoke((Action)(() => { this.chkAll.IsChecked = false; this.mpr.IsActive = true; this.dtgCustomer.Visibility = System.Windows.Visibility.Hidden; this.tblTotal.Text = FindResource("total_zero").ToString(); dtgCustomer.Items.Refresh(); })); dt_customer.Clear(); dt_customer = bus_tb_customer.GetCustomerFollowPaging(be_limit, af_limit, con1, con2, StaticClass.GeneralClass.flag_database_type_general); int no = paging_number_previous - 1; foreach (DataRow datarow in dt_customer.Rows) { no++; EC_tb_Customer ec_tb_customer = new EC_tb_Customer(); ec_tb_customer.No = no; ec_tb_customer.CustomerID = Convert.ToInt32(datarow["CustomerID"].ToString()); ec_tb_customer.FirstName = datarow["FirstName"].ToString(); ec_tb_customer.LastName = datarow["LastName"].ToString(); ec_tb_customer.FullName = datarow["FirstName"].ToString() + " " + datarow["LastName"].ToString(); ec_tb_customer.Address1 = datarow["Address1"].ToString(); ec_tb_customer.Address2 = datarow["Address2"].ToString(); ec_tb_customer.City = datarow["City"].ToString(); ec_tb_customer.State = datarow["State"].ToString(); ec_tb_customer.Zipcode = datarow["Zipcode"].ToString(); ec_tb_customer.Phone = datarow["Phone"].ToString(); ec_tb_customer.Email = datarow["Email"].ToString(); ec_tb_customer.CheckDel = false; ec_tb_customer.ImageUrl = @"pack://application:,,,/Resources/edit.png"; list_ec_tb_customer.Add(ec_tb_customer); } Thread.Sleep(500); this.Dispatcher.Invoke((Action)(() => { dtgCustomer.Items.Refresh(); tblTotal.Text = FindResource("total").ToString() + "(" + list_ec_tb_customer.Count.ToString() + ")"; })); //if is added if (add == true) { this.dtgCustomer.Dispatcher.Invoke((Action)(() => { dtgCustomer.SelectedIndex = list_ec_tb_customer.Count - 1; dtgCustomer.ScrollIntoView(dtgCustomer.Items.GetItemAt(list_ec_tb_customer.Count - 1)); })); } //if edited if (_row_selected > -1) { this.dtgCustomer.Dispatcher.Invoke((Action)(() => { dtgCustomer.SelectedIndex = _row_selected; dtgCustomer.ScrollIntoView(dtgCustomer.Items.GetItemAt(_row_selected)); })); } this.mpr.Dispatcher.Invoke((Action)(() => { this.mpr.IsActive = false; })); this.dtgCustomer.Dispatcher.Invoke((Action)(() => { this.dtgCustomer.Visibility = System.Windows.Visibility.Visible; })); } catch (Exception ex) { this.Dispatcher.Invoke((Action)(() => { ModernDialog md = new ModernDialog(); md.CloseButton.Content = FindResource("close").ToString(); md.Title = FindResource("notification").ToString(); md.Content = ex.Message + "!"; md.ShowDialog(); })); } }); thread_content.Start(); } }