private void CopyAssets(TblAsset newRow, int times) { using (var context = new WorkFlowManagerDBEntities()) { for (int i = 0; i < times; i++) { var row = new TblAsset { Aname = newRow.Aname, Ename = newRow.Ename, Notes = newRow.Notes, Code = GetMaxAssets(), PurchasePrice = newRow.PurchasePrice, Disposable = newRow.Disposable, YearOfProduct = newRow.YearOfProduct, TblAssetsType = newRow.TblAssetsType, TblHardDisk = newRow.TblHardDisk, TblMemory = newRow.TblMemory, TblProcessor = newRow.TblProcessor, TechSpec = newRow.TechSpec, }; context.TblAssets.AddObject(row); context.SaveChanges(); } } }
public void CopyAsset() { var saveRow = new TblAsset(); saveRow.InjectFrom(SelectedMainRow); saveRow.Iserial = 0; saveRow.Code = ""; Client.CopyAssetsAsync(saveRow, CopyTimes); }
private int DeleteTblAssets(TblAsset row) { using (var context = new WorkFlowManagerDBEntities()) { var oldRow = (from e in context.TblAssets where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldRow != null) { context.DeleteObject(oldRow); } context.SaveChanges(); } return(row.Iserial); }
private TblAsset UpdateOrInsertTblAssets(TblAsset newRow, bool save, int index, out int outindex) { outindex = index; using (var context = new WorkFlowManagerDBEntities()) { if (save) { context.TblAssets.AddObject(newRow); } else { var oldRow = (from e in context.TblAssets where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, context); } } context.SaveChanges(); return(newRow); } }
public void SaveMainRow() { if (SelectedMainRow != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (isvalid) { var save = SelectedMainRow.Iserial == 0; if (save) { if (AllowAdd != true) { MessageBox.Show(strings.AllowAddMsg); return; } } else { if (AllowUpdate != true) { MessageBox.Show(strings.AllowUpdateMsg); return; } } var saveRow = new TblAsset(); if (AssetsTypeList != null && SelectedMainRow.TblAssetsType == null) { SelectedMainRow.AssetTypePerRow = AssetsTypeList.FirstOrDefault(x => x.Code == "N/A"); if (SelectedMainRow.AssetTypePerRow != null) { SelectedMainRow.TblAssetsType = SelectedMainRow.AssetTypePerRow.Iserial; } } if (HardDiskList != null && SelectedMainRow.TblHardDisk == 0) { SelectedMainRow.HardDiskPerRow = HardDiskList.FirstOrDefault(x => x.Code == "N/A"); if (SelectedMainRow.HardDiskPerRow != null) { SelectedMainRow.TblHardDisk = SelectedMainRow.HardDiskPerRow.Iserial; } } if (MemoryList != null && SelectedMainRow.TblMemory == 0) { SelectedMainRow.MemoryPerRow = MemoryList.FirstOrDefault(x => x.Code == "N/A"); if (SelectedMainRow.MemoryPerRow != null) { SelectedMainRow.TblMemory = SelectedMainRow.MemoryPerRow.Iserial; } } if (ProcessorList != null && SelectedMainRow.TblProcessor == 0) { SelectedMainRow.ProcessorPerRow = ProcessorList.FirstOrDefault(x => x.Code == "N/A"); if (SelectedMainRow.ProcessorPerRow != null) { SelectedMainRow.TblProcessor = SelectedMainRow.ProcessorPerRow.Iserial; } } saveRow.InjectFrom(SelectedMainRow); Client.UpdateOrInsertTblAssetsAsync(saveRow, save, 0); } else { MessageBox.Show("Data Was Not Saved"); } } }