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(); } }
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(); } }