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 bool CheckConditionNumberAgency(string rule, AddStoreWindow para) { int count = 0; string district = para.txtDistrict.Text; count = DataProvider.Instance.DB.Agencies.Where(x => x.District == district).Where(x => x.IsDelete == false).Count(); if (count >= int.Parse(rule)) { return false; } return true; }
private void OpenAddStoreWindow() { AddStoreWindow wd = new AddStoreWindow(); try { string query = "SELECT * FROM Agency"; Agency store = DataProvider.Instance.DB.Agencies.SqlQuery(query).Last(); wd.txtID.Text = (store.ID + 1).ToString(); } catch { wd.txtID.Text = "1"; } finally { wd.ShowDialog(); } }
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(); } }