private void OpenEditStoreWindow(String para) { Agency store = new Agency(); int id = int.Parse(para); store = (Agency)DataProvider.Instance.DB.Agencies.Where(x => x.ID == id).First(); int pos = 0; int typeA = int.Parse(store.TypeOfAgency.ToString()); TypeOfAgency type = (TypeOfAgency)DataProvider.Instance.DB.TypeOfAgencies.Where(x => x.ID == typeA).First(); AddStoreWindow wd = new AddStoreWindow(); wd.txtID.Text = store.ID.ToString(); wd.txtName.Text = store.Name.ToString(); wd.txtDistrict.Text = store.District.ToString(); wd.txtAddress.Text = store.Address.ToString(); wd.txtEmail.Text = store.Email.ToString(); wd.txtCheckin.Text = store.CheckIn.ToString(); wd.txtPhone.Text = store.PhoneNumber.ToString(); for (int i = 0; i < wd.txtSpecies.Items.Count; i++) { wd.txtSpecies.SelectedIndex = i; if (wd.txtSpecies.Text.ToString() == type.Name) pos = i; } wd.txtSpecies.SelectedIndex = pos; wd.txtDebt.Text = SeparateThousands(store.Debt.ToString()); wd.Title = "Sửa thông tin đại lý"; wd.txtDebt.IsEnabled = false; wd.txtCheckin.IsEnabled = false; wd.ShowDialog(); }
private void ReLoad3Stores(HomeWindow para, List<Agency> listStores, int pageNumber) { para.grdStoreFisrt.Children.Clear(); para.grdStoreSecond.Children.Clear(); para.grdStoreThird.Children.Clear(); string query = "SELECT * FROM AGENCY WHERE ISDELETE = 0"; this.ListStores = DataProvider.Instance.DB.Agencies.SqlQuery(query).ToList(); //hiển thị ds theo phân trang(number page) for (int i = 0; i < 3; i++) { int pos = (pageNumber - 1) * 3 + i; if (pos == this.ListStores.Count) break; int typeA = int.Parse(ListStores[pos].TypeOfAgency.ToString()); TypeOfAgency type = (TypeOfAgency)DataProvider.Instance.DB.TypeOfAgencies.Where(x => x.ID == typeA).First(); StoreControlUC uc = new StoreControlUC(); uc.Height = 350; uc.Width = 280; uc.txbID.Text = ListStores[pos].ID.ToString(); uc.AgencyName.Text = ListStores[pos].Name.ToString(); uc.txbAgencyPhone.Text = ListStores[pos].PhoneNumber.ToString(); uc.txbAgencyDate.Text = ListStores[pos].CheckIn.Value.ToShortDateString(); uc.txbAgencyPosition.Text = ListStores[pos].Address.ToString(); uc.txbAgencyType.Text = type.Name.ToString(); switch (i) { case 0: para.grdStoreFisrt.Children.Add(uc); break; case 1: para.grdStoreSecond.Children.Add(uc); break; case 2: para.grdStoreThird.Children.Add(uc); break; } } }
private void SaveStore(AddStoreWindow para) { StreamReader sr = new StreamReader("../../cache.txt"); string cache = sr.ReadToEnd(); sr.Close(); string[] rulesSetting = cache.Split(' '); if (string.IsNullOrEmpty(para.txtName.Text)) { para.txtName.Focus(); return; } if (string.IsNullOrEmpty(para.txtAddress.Text)) { para.txtAddress.Focus(); return; } if (string.IsNullOrEmpty(para.txtCheckin.Text)) { para.txtCheckin.Focus(); return; } if (string.IsNullOrEmpty(para.txtDebt.Text)) { para.txtDebt.Focus(); return; } if (string.IsNullOrEmpty(para.txtEmail.Text)) { para.txtEmail.Focus(); return; } if (string.IsNullOrEmpty(para.txtDistrict.Text)) { para.txtDistrict.Focus(); return; } if (string.IsNullOrEmpty(para.txtPhone.Text) || para.txtPhone.Text.Length != 10) { para.txtPhone.Focus(); return; } if (string.IsNullOrEmpty(para.txtSpecies.Text)) { para.txtSpecies.Focus(); return; } if (DataProvider.Instance.DB.Agencies.Where(x => x.IsDelete == false).Where(x => x.District == para.txtDistrict.Text).ToList().Count <= 0) { var results = DataProvider.Instance.DB.Agencies.Where(x => x.IsDelete == false).Select(x => x.District).Distinct().ToList(); if (results.Count >= 20) { MessageBox.Show("Exceed the number of districts limit: 20"); return; } } if (!CheckConditionNumberAgency(rulesSetting[1], para) && para.Title == "Thêm đại lý") { MessageBox.Show("Number of agency in this district is full"); return; } TypeOfAgency type = (TypeOfAgency)DataProvider.Instance.DB.TypeOfAgencies.Where(x => x.Name == para.txtSpecies.Text).First(); if (type.MaxOfDebt < ConvertToNumber(para.txtDebt.Text)) { MessageBox.Show("Nợ vượt quá cho phép."); return; } try { Agency item = new Agency(); item.ID = int.Parse(para.txtID.Text); item.Name = para.txtName.Text; item.PhoneNumber = para.txtPhone.Text; item.Address = para.txtAddress.Text; item.District = para.txtDistrict.Text; item.Debt = ConvertToNumber(para.txtDebt.Text); item.CheckIn = DateTime.Parse(para.txtCheckin.Text); item.TypeOfAgency = type.ID; item.Email = para.txtEmail.Text; item.IsDelete = false; DataProvider.Instance.DB.Agencies.AddOrUpdate(item); DataProvider.Instance.DB.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (this.HomeWindow.grdList3Store_Store.Visibility == Visibility.Visible) { PageNumber = 1; Load3Stores(this.HomeWindow, this.ListStores, PageNumber); } else { LoadListAgency(); } para.Close(); } }
private void SearchAgency(HomeWindow para) { if (para.grdListStore_Store.Visibility == Visibility.Visible) { foreach (AgencyControlUC control in HomeWindow.stkStore_Store.Children) { if (!control.txtName.Text.ToLower().Contains(this.HomeWindow.txtSearchAgency.Text)) { control.Visibility = Visibility.Collapsed; } else { control.Visibility = Visibility.Visible; } } } else { int loadPos = 0; int i = 0; int pos = 0; string query = "SELECT * FROM AGENCY WHERE ISDELETE = 0"; this.ListStores = DataProvider.Instance.DB.Agencies.SqlQuery(query).ToList(); if (String.IsNullOrEmpty(this.HomeWindow.txtSearchAgency.Text)) { Load3Stores(para, this.ListStores, PageNumber); } else { para.grdStoreFisrt.Children.Clear(); para.grdStoreSecond.Children.Clear(); para.grdStoreThird.Children.Clear(); //hiển thị ds theo phân trang(number page) while (i < 3) { for (pos = loadPos; pos < this.ListStores.Count; pos++) { if (this.ListStores[pos].Name.ToLower().Contains(this.HomeWindow.txtSearchAgency.Text.ToLower())) { i++; loadPos = pos + 1; int typeA = int.Parse(ListStores[pos].TypeOfAgency.ToString()); TypeOfAgency type = (TypeOfAgency)DataProvider.Instance.DB.TypeOfAgencies.Where(x => x.ID == typeA).First(); StoreControlUC uc = new StoreControlUC(); uc.Height = 350; uc.Width = 280; uc.txbID.Text = ListStores[pos].ID.ToString(); uc.AgencyName.Text = ListStores[pos].Name.ToString(); uc.txbAgencyPhone.Text = ListStores[pos].PhoneNumber.ToString(); uc.txbAgencyDate.Text = ListStores[pos].CheckIn.Value.ToShortDateString(); uc.txbAgencyPosition.Text = ListStores[pos].Address.ToString(); uc.txbAgencyType.Text = type.Name.ToString(); switch (i - 1) { case 0: para.grdStoreFisrt.Children.Add(uc); break; case 1: para.grdStoreSecond.Children.Add(uc); break; case 2: para.grdStoreThird.Children.Add(uc); break; } } } if (pos == this.ListStores.Count) { break; } } } } }