public void AddNewMainRow(bool checkLastRow) { var currentRowIndex = (MainRowList.IndexOf(SelectedMainRow)); if (checkLastRow) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (!isvalid) { return; } } if (AllowAdd != true) { MessageBox.Show(strings.AllowAddMsg); return; } var newrow = new TblshopareaModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public void SaveOldRow(TblshopareaModel oldRow) { if (oldRow != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(oldRow, new ValidationContext(oldRow, null, null), valiationCollection, true); if (isvalid) { var save = oldRow.Iserial == 0; if (AllowUpdate != true && !save) { MessageBox.Show(strings.AllowUpdateMsg); return; } var saveRow = new shoparea(); saveRow.InjectFrom(oldRow); if (!Loading) { Loading = true; Glclient.UpdateOrInsertshopareaAsync(saveRow, save, MainRowList.IndexOf(oldRow), LoggedUserInfo.DatabasEname); } } } }
public ShopAreaViewModel() { if (!IsDesignTime) { GetItemPermissions(PermissionItemName.ShopArea.ToString()); Glclient = new GlServiceClient(); var costDimSetupTypeClient = new GlServiceClient(); costDimSetupTypeClient.GetGenericCompleted += (s, sv) => { BrandList = sv.Result; }; costDimSetupTypeClient.GetGenericAsync("TblItemDownLoadDef", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); Glclient.GetRetailChainSetupByCodeAsync("ShopAreaCostCenterType", LoggedUserInfo.DatabasEname); Glclient.GetRetailChainSetupByCodeCompleted += (s, sv) => { int costcentertype = Convert.ToInt32(sv.Result.sSetupValue); Glclient.GetTblCostCenterAsync(MainRowList.Count, PageSize, costcentertype, "it.Iserial", null, null, LoggedUserInfo.DatabasEname, LoggedUserInfo.Iserial, 0, 0); }; Glclient.GetTblCostCenterCompleted += (s, sv) => { CostCenterList = sv.Result; }; MainRowList = new ObservableCollection <TblshopareaModel>(); SelectedMainRow = new TblshopareaModel(); Glclient.GetshopareaCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblshopareaModel(); newrow.InjectFrom(row); var storeTempRow = sv.StoreList.FirstOrDefault(w => w.code == row.shopcode); if (storeTempRow != null) { newrow.StorePerRow = new CRUDManagerService.StoreForAllCompany() { Code = storeTempRow.code, Aname = storeTempRow.aname, Ename = storeTempRow.ENAME, }; } newrow.BrandPerRow = new GenericTable(); var BrandTempRow = sv.BrandList.FirstOrDefault(w => w.Code == row.Brand); newrow.BrandPerRow = new GenericTable() { Code = BrandTempRow.Code, Aname = BrandTempRow.Aname, Ename = BrandTempRow.Ename, }; MainRowList.Add(newrow); } Loading = false; FullCount = sv.fullCount; if (MainRowList.Any() && (SelectedMainRow == null)) { SelectedMainRow = MainRowList.FirstOrDefault(); } if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } if (Export) { Export = false; AllowExport = true; //ExportGrid.ExportExcel("Account"); } }; Glclient.UpdateOrInsertshopareaCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } Loading = false; }; Glclient.DeleteshopareaCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { MainRowList.Remove(oldrow); } if (!MainRowList.Any()) { AddNewMainRow(false); } }; Glclient.GetTblCostCenterShopAreaCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblCostCenterShopAreaModel(); newrow.InjectFrom(row); var storeTempRow = CostCenterList.FirstOrDefault(w => w.Iserial == row.TblCostCenter); if (storeTempRow != null) { newrow.CostCenterPerRow = new TblCostCenter() { Code = storeTempRow.Code, Aname = storeTempRow.Aname, Ename = storeTempRow.Ename, TblCostCenterType = storeTempRow.TblCostCenterType }; } SelectedMainRow.DetailsList.Add(newrow); } Loading = false; DetailFullCount = sv.fullCount; if (SelectedMainRow.DetailsList.Any() && (SelectedDetailRow == null)) { SelectedDetailRow = SelectedMainRow.DetailsList.FirstOrDefault(); } if (DetailFullCount == 0 && SelectedMainRow.DetailsList.Count == 0) { AddNewDetailRow(false); } }; Glclient.UpdateOrInsertTblCostCenterShopAreasCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { SelectedMainRow.DetailsList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } Loading = false; }; Glclient.DeleteTblCostCenterShopAreaCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } var oldrow = SelectedMainRow.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { SelectedMainRow.DetailsList.Remove(oldrow); } if (!MainRowList.Any()) { AddNewDetailRow(false); } }; GetMaindata(); } }