private void LoadSettingWindow(HomeWindow para) { this.HomeWindow = para; this.ListType = DataProvider.Instance.DB.TypeOfAgencies.ToList <TypeOfAgency>(); StreamReader sr = new StreamReader("../../cache.txt"); this.cache = sr.ReadToEnd(); sr.Close(); string[] rulesSetting = this.cache.Split(' '); para.txtNumberType_Setting.Text = rulesSetting[0]; para.txtNumberAgencyinDistrict_Setting.Text = rulesSetting[1]; para.txtNumberProduct_Setting.Text = rulesSetting[2]; para.txtNumberUnit_Setting.Text = rulesSetting[3]; for (int i = 0; i < this.ListType.Count; i++) { TypeOfAgencyUC uc = new TypeOfAgencyUC(); uc.txbSTT.Text = (i + 1).ToString(); uc.txbName.Text = this.ListType[i].Name; uc.txbDebt.Text = SeparateThousands(this.ListType[i].MaxOfDebt.ToString()); para.stkListType_Setting.Children.Add(uc); } Button bt = new Button(); bt = (Button)para.stkListType_Setting.Children[0]; para.stkListType_Setting.Children.RemoveAt(0); para.stkListType_Setting.Children.Add(bt); }
private void DeleteType(TypeOfAgencyUC para) { MessageBoxResult mes = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButton.YesNo); if (mes != MessageBoxResult.Yes) { return; } List <Agency> list = DataProvider.Instance.DB.Agencies.Where(x => x.IsDelete == false).ToList(); int stt = int.Parse(para.txbSTT.Text); foreach (Agency item in list) { if (item.TypeOfAgency == this.ListType[stt - 1].ID) { MessageBox.Show("You must delete all agencies of this type"); return; } } TypeOfAgency type = this.ListType[stt - 1]; DataProvider.Instance.DB.TypeOfAgencies.Remove(type); DataProvider.Instance.DB.SaveChanges(); int count = this.HomeWindow.stkListType_Setting.Children.Count; for (int i = 0; i < count - 1; i++) { this.HomeWindow.stkListType_Setting.Children.RemoveAt(0); } LoadSettingWindow(this.HomeWindow); }
private void EditType(TypeOfAgencyUC para) { int stt = int.Parse(para.txbSTT.Text); this.ListType = DataProvider.Instance.DB.TypeOfAgencies.ToList(); AddTypeOfAgencyWindow wd = new AddTypeOfAgencyWindow(); wd.txtID.Text = this.ListType[stt - 1].ID.ToString(); wd.txtName.Text = this.ListType[stt - 1].Name; wd.txtDebt.Text = SeparateThousands(this.ListType[stt - 1].MaxOfDebt.ToString()); wd.ShowDialog(); }