/// <summary> /// 保存导入的数据(仅限LH.武汉站) /// </summary> /// <param name="bill"></param> /// <returns></returns> public string SaveImport(GiveBill bill) { try { //查询数据库中有没有重复项 if (CurrentDal.LoadEntities(a => a.LBBillCode == bill.LBBillCode).Count() > 0) { return(bill.LBBillCode + "导入失败!客户单号重复!\r\n"); } ; //主表 bill.Id = Guid.NewGuid(); //生成一个id bill.BillCode = GetBillCode("JH"); //生成单号 if (bill.BillCode == "no") { bill.BillCode = GetBillCode("JH"); //再次生成单号 } bill.BillState = 1; //保存状态 bill.CreateDate = DateTime.Now; bill.MakePerson = HttpContext.Current.Session["UserName"].ToString(); bill.LoadGoodsType = "武汉-配送客户出库装货"; bill.BackLoadGoodsType = "武汉-客户现场卸货"; bill.OutputType = "配送交货出库"; bill.OutputTypeId = 20; bill.BusinessType = "武汉-二次配送"; bill.Department = "LH.武汉站"; bill.DepartmentId = "LH7011"; bill.Company = "联合运输"; bill.CompanyId = "LH0000"; bill.Remark = "批量导入"; //子表 foreach (var item in bill.Record)//生成子表id { item.Id = Guid.NewGuid(); item.Department = bill.Department; item.DepartmentId = bill.DepartmentId; item.State = bill.BillState; item.CreateDate = bill.CreateDate; item.InOrOut = 0; item.MainTableType = "GiveBill"; item.InOutTypeId = bill.OutputTypeId; item.InOutTypeName = bill.OutputType; var goodItem = CurrentDBSession.GoodItemDal.LoadEntities(a => a.ItemCode == item.ItemCode).FirstOrDefault(); item.ItemLine = goodItem.ItemLine; item.ItemName = goodItem.ItemName; item.ItemSpecifications = goodItem.ItemSpecifications; item.ItemUnit = goodItem.ItemUnit; item.UnitWeight = goodItem.UnitWeight; item.Remark = bill.Remark; } CurrentDal.AddEntity(bill); return(CurrentDBSession.SaveChanges() ? "" : bill.LBBillCode + "导入失败!\r\n"); } catch (Exception) { return(bill.LBBillCode + "导入失败!\r\n"); } }
/// <summary> /// 保存表单数据 /// </summary> /// <returns></returns> public string SaveData(OtherOutput bill) { //主表id为0 新增一条记录 此时子表数据会自动插入 if (bill.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { bill.Id = Guid.NewGuid(); //生成一个id bill.BillState = 1; //保存状态 foreach (var item in bill.Record) //生成子表id { if (item.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { item.Id = Guid.NewGuid(); item.Department = bill.Department; item.DepartmentId = bill.DepartmentId; item.WarehouseId = bill.WarehouseId; item.Warehouse = bill.Warehouse; item.State = bill.BillState; item.CreateDate = DateTime.Now; item.InOrOut = 0; } } CurrentDal.AddEntity(bill); } //主表有id 说明是修改的 else { //删除原子表数据 List <Record> list = CurrentDBSession.RecordDal.LoadEntities(a => a.MainTableId == bill.Id).ToList(); foreach (Record item in list) { CurrentDBSession.RecordDal.DeleteEntity(item); //RecordService.DeleteEntity(item); } //添加子表数据 foreach (Record record in bill.Record) { if (record.Id == Guid.Parse("00000000-0000-0000-0000-000000000000") || record.Id == Guid.Empty) { record.Id = Guid.NewGuid(); //设置子表id record.MainTableId = bill.Id; //设置主表id record.Department = bill.Department; record.DepartmentId = bill.DepartmentId; record.WarehouseId = bill.WarehouseId; record.Warehouse = bill.Warehouse; record.State = bill.BillState; record.CreateDate = DateTime.Now; record.InOrOut = 0; } CurrentDBSession.RecordDal.AddEntity(record); //RecordService.AddEntity(record); } //修改主表数据 CurrentDal.EditEntity(bill); } return(CurrentDBSession.SaveChanges() ? bill.Id.ToString() : "no"); }
public string SaveData(TaskBill bill, string[] records) { //主表id为0 新增一条记录 此时子表数据会自动插入 if (bill.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { bill.Id = Guid.NewGuid();//生成一个id //bill.BillCode = GetBillCode("RW");//生成单号 //if (bill.BillCode == "no") //{ // bill.BillCode = GetBillCode("RW");//再次生成单号 //} bill.BillState = 1;//保存状态 if (records != null) { //修改对应交货单的任务单字段 List <GiveBill> list = CurrentDBSession.GiveBillDal.LoadEntities(a => records.Contains(a.BillCode)).ToList(); foreach (GiveBill item in list) { item.TaskBillCode = bill.BillCode; CurrentDBSession.GiveBillDal.EditEntity(item);//设置交货单的任务单号 } } CurrentDal.AddEntity(bill); } else //主表有id 说明是修改的 { List <GiveBill> list; //把原来属于但是现在不属于这张任务单的交货单清空 if (records != null) //修改后子表有记录 { list = CurrentDBSession.GiveBillDal.LoadEntities(a => (a.TaskBillCode == bill.BillCode) && (!records.Contains(a.BillCode))).ToList(); } else //修改后子表全删除了 { list = CurrentDBSession.GiveBillDal.LoadEntities(a => a.TaskBillCode == bill.BillCode).ToList(); } foreach (var item in list) { item.TaskBillCode = null; CurrentDBSession.GiveBillDal.EditEntity(item); } if (records != null) { //设置交货单的任务单号 var list1 = CurrentDBSession.GiveBillDal.LoadEntities(a => records.Contains(a.BillCode)); foreach (var item in list1) { item.TaskBillCode = bill.BillCode; CurrentDBSession.GiveBillDal.EditEntity(item); } } //修改主表数据 CurrentDal.EditEntity(bill); } //保存成功返回单据Id return(CurrentDBSession.SaveChanges() ? bill.Id.ToString() : "no"); }
/// <summary> /// 创建组织对象并添加组织 /// </summary> /// <param name="organizationName">组织名称</param> /// <param name="password">组织密码</param> /// <param name="userAuth">组织成员默认权限</param> /// <returns>组织对象</returns> public OrganizationInfo AddOrganization(string organizationName, string password, UserAuth userAuth) { OrganizationInfo organizationInfo = new OrganizationInfo() { ID = Guid.NewGuid(), OrganizationName = organizationName, Password = password, DefaultUserAuth = userAuth }; CurrentDal.AddEntity(organizationInfo); return(organizationInfo); }
public T AddEntity(T entity) { CurrentDal.AddEntity(entity); bool b = CurrentDBSession.SaveChanges(); if (!b) { throw new Exception("sql语句执行失败"); } return(entity); }
public T Add(T entity) { try { CurrentDal.AddEntity(entity); DbSession.SaveChanges(); return(entity); } catch (Exception ex) { throw; } }
public string Save(CheckBill CheckBill, string userName) { //主表id为0 新增一条记录 此时子表数据会自动插入 if (CheckBill.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { CheckBill.Id = Guid.NewGuid(); //生成一个id CheckBill.BillCode = GetBillCode("PD"); //生成单号 if (CheckBill.BillCode == "no") { CheckBill.BillCode = GetBillCode("PD"); //再次生成单号 } CheckBill.BillState = 1; //保存状态 CheckBill.MakePerson = userName; CheckBill.CreateDate = DateTime.Now; foreach (var item in CheckBill.CheckDetail) //生成子表id { item.Id = Guid.NewGuid(); //重置子表Id item.CreateDate = DateTime.Now; item.State = 1; item.MainTableId = CheckBill.Id; } CurrentDal.AddEntity(CheckBill); } //主表有id 说明是修改的 else { //删除原子表数据 List <CheckDetail> list = CurrentDBSession.CheckDetailDal.LoadEntities(a => a.MainTableId == CheckBill.Id).ToList(); foreach (CheckDetail item in list) { CurrentDBSession.CheckDetailDal.DeleteEntity(item); } //添加子表数据 foreach (CheckDetail item in CheckBill.CheckDetail) { item.Id = Guid.NewGuid(); //设置子表id item.MainTableId = CheckBill.Id; //设置主表id item.CreateDate = DateTime.Now; item.State = 1; CurrentDBSession.CheckDetailDal.AddEntity(item); } //修改主表数据 CheckBill.MakePerson = userName; CheckBill.CreateDate = DateTime.Now; CurrentDal.EditEntity(CheckBill); } //保存成功返回单据Id return(CurrentDBSession.SaveChanges() ? CheckBill.Id.ToString() : "no"); }
/// <summary> /// 增删改 /// </summary> /// <param name="insertedList"></param> /// <param name="updatedList"></param> /// <param name="deletedList"></param> public void CUD(List <TBL_ZDCQ_ZFHBBT> insertedList, List <TBL_ZDCQ_ZFHBBT> updatedList, List <TBL_ZDCQ_ZFHBBT> deletedList, decimal?year) { if (year == null) { return; } foreach (var item in insertedList) { item.YEAR = year; CurrentDal.AddEntity(item); } foreach (var item in updatedList) { item.YEAR = year; CurrentDal.EditEntity(item); } foreach (var item in deletedList) { CurrentDal.DeleteEntity(item); } CurrentDBSession.SaveChanges(); }
/// <summary> /// 保存表单数据 /// </summary> /// <returns></returns> public string SaveData(DIYBill bill, List <Record> recordlist1, List <Record> recordlist2) { //主表id为0 新增一条记录 此时子表数据会自动插入 if (bill.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { bill.Id = Guid.NewGuid(); //生成一个id bill.BillState = 1; //保存状态 foreach (Record record1 in recordlist1) { record1.Id = Guid.NewGuid(); record1.MainTableId = bill.Id; record1.CreateDate = DateTime.Now; record1.State = 1; record1.Department = bill.Department; record1.DepartmentId = bill.DepartmentId; record1.InOrOut = 0; CurrentDBSession.RecordDal.AddEntity(record1); } foreach (Record record2 in recordlist2) { record2.Id = Guid.NewGuid(); record2.MainTableId = bill.Id; record2.CreateDate = DateTime.Now; record2.State = 1; record2.Department = bill.Department; record2.DepartmentId = bill.DepartmentId; record2.InOrOut = 1; CurrentDBSession.RecordDal.AddEntity(record2); } CurrentDal.AddEntity(bill); } //主表有id 说明是修改的 else { //删除原子表数据 List <Record> list = CurrentDBSession.RecordDal.LoadEntities(a => a.MainTableId == bill.Id).ToList(); foreach (Record item in list) { CurrentDBSession.RecordDal.DeleteEntity(item); } //添加子表数据 foreach (Record record1 in recordlist1) { record1.Id = Guid.NewGuid(); record1.MainTableId = bill.Id; record1.CreateDate = DateTime.Now; record1.State = 1; record1.Department = bill.Department; record1.DepartmentId = bill.DepartmentId; record1.InOrOut = 0; CurrentDBSession.RecordDal.AddEntity(record1); CurrentDBSession.RecordDal.AddEntity(record1); } foreach (Record record2 in recordlist2) { record2.Id = Guid.NewGuid(); record2.MainTableId = bill.Id; record2.CreateDate = DateTime.Now; record2.State = 1; record2.Department = bill.Department; record2.DepartmentId = bill.DepartmentId; record2.InOrOut = 1; CurrentDBSession.RecordDal.AddEntity(record2); } //修改主表数据 CurrentDal.EditEntity(bill); } return(CurrentDBSession.SaveChanges() ? bill.Id.ToString() : "no"); }
public T AddEntity(T entity) { CurrentDal.AddEntity(entity); DbSession.SaveChanges(); return(entity); }
/// <summary> /// 保存表单数据 /// </summary> /// <returns></returns> public string SaveData(OtherExpenseList bill, int billType) { //主表id为0 新增一条记录 此时子表数据会自动插入 if (bill.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { bill.Id = Guid.NewGuid();//生成一个id if (billType == 1) { bill.BillCode = GetBillCode("QS");//生成单号 其他费收入 if (bill.BillCode == "no") { bill.BillCode = GetBillCode("QS");//再次生成单号 } } if (billType == 2) { bill.BillCode = GetBillCode("QF");//生成单号 其他成本 if (bill.BillCode == "no") { bill.BillCode = GetBillCode("QF");//再次生成单号 } } bill.BillState = 1;//保存状态 bill.BillType = billType; bill.CreateDate = DateTime.Now; foreach (var item in bill.OtherExpenseListDetail)//生成子表id { if (item.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { item.Id = Guid.NewGuid(); } item.MainTableId = bill.Id; item.Department = bill.Department; item.DepartmentId = bill.DepartmentId; item.Company = bill.Company; item.CompanyId = bill.CompanyId; item.State = 1; item.RecorkType = billType; item.CreateDate = DateTime.Now; } CurrentDal.AddEntity(bill); } //主表有id 说明是修改的 else { //删除原子表数据 List <OtherExpenseListDetail> list = CurrentDBSession.OtherExpenseListDetailDal.LoadEntities(a => a.MainTableId == bill.Id).ToList(); foreach (OtherExpenseListDetail item in list) { CurrentDBSession.OtherExpenseListDetailDal.DeleteEntity(item); } //添加子表数据 foreach (OtherExpenseListDetail record in bill.OtherExpenseListDetail) { if (record.Id == Guid.Parse("00000000-0000-0000-0000-000000000000") || record.Id == Guid.Empty) { record.Id = Guid.NewGuid(); //设置子表id } record.MainTableId = bill.Id; //设置主表id record.Department = bill.Department; record.DepartmentId = bill.DepartmentId; record.Company = bill.Company; record.CompanyId = bill.CompanyId; record.State = 1; record.RecorkType = billType; record.CreateDate = DateTime.Now; CurrentDBSession.OtherExpenseListDetailDal.AddEntity(record); } //修改主表数据 CurrentDal.EditEntity(bill); } return(CurrentDBSession.SaveChanges() ? bill.Id.ToString() : "no"); }
/// <summary> /// 保存表单数据 /// </summary> /// <returns></returns> public string SaveData(LocationChange bill, List <LocationChangeRecordView> LocationChangeRecordView) { //主表id为0 新增一条记录 此时子表数据会自动插入 if (bill.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { bill.Id = Guid.NewGuid(); //生成一个id bill.BillCode = GetBillCode("HW"); //生成单号 if (bill.BillCode == "no") { bill.BillCode = GetBillCode("HW"); //再次生成单号 } bill.BillState = 1; //保存状态 if (LocationChangeRecordView != null) { foreach (var lcrv in LocationChangeRecordView) { Record cd = new Record(); cd.Id = Guid.NewGuid(); cd.MainTableId = bill.Id; cd.Count = lcrv.Count; cd.CreateDate = DateTime.Now; cd.Department = bill.Department; cd.DepartmentId = bill.DepartmentId; cd.State = 1; cd.ItemBatch = lcrv.ItemBatch; cd.ItemCode = lcrv.ItemCode; cd.ItemLine = lcrv.ItemLine; cd.ItemName = lcrv.ItemName; cd.ItemSpecifications = lcrv.ItemSpecifications; cd.ItemUnit = lcrv.ItemUnit; cd.UnitWeight = lcrv.UnitWeight; cd.Weight = lcrv.Weight; cd.ItemLocation = lcrv.LocationChangeAfter; cd.ItemLocationId = lcrv.LocationChangeAfterId; cd.InOrOut = 1; cd.MainTableType = "LocationChange"; cd.Warehouse = lcrv.WarehouseAfter; cd.WarehouseId = lcrv.WarehouseAfterId; cd.InOutTypeId = bill.InputTypeId; cd.InOutTypeName = bill.InputType; CurrentDBSession.RecordDal.AddEntity(cd); Record cd2 = new Record(); cd2.Id = Guid.NewGuid(); cd2.MainTableId = bill.Id; cd2.Count = lcrv.Count; cd2.CreateDate = DateTime.Now; cd2.Department = bill.Department; cd2.DepartmentId = bill.DepartmentId; cd2.State = 1; cd2.ItemBatch = lcrv.ItemBatch; cd2.ItemCode = lcrv.ItemCode; cd2.ItemLine = lcrv.ItemLine; cd2.ItemName = lcrv.ItemName; cd2.ItemSpecifications = lcrv.ItemSpecifications; cd2.ItemUnit = lcrv.ItemUnit; cd2.UnitWeight = lcrv.UnitWeight; cd2.Weight = lcrv.Weight; cd2.ItemLocation = lcrv.LocationChangeBefore; cd2.ItemLocationId = lcrv.LocationChangeBeforeId; cd2.InOrOut = 0; cd2.MainTableType = "LocationChange"; cd2.Warehouse = lcrv.WarehouseBefore; cd2.WarehouseId = lcrv.WarehouseBeforeId; cd2.InOutTypeId = bill.OutputTypeId; cd2.InOutTypeName = bill.OutputType; CurrentDBSession.RecordDal.AddEntity(cd2); } } CurrentDal.AddEntity(bill); } //主表有id 说明是修改的 else { //删除原子表数据 List <Record> list = CurrentDBSession.RecordDal.LoadEntities(a => a.MainTableId == bill.Id).ToList(); foreach (Record item in list) { CurrentDBSession.RecordDal.DeleteEntity(item); //RecordService.DeleteEntity(item); } //添加子表数据 if (LocationChangeRecordView != null) { foreach (var lcrv in LocationChangeRecordView) { Record cd = new Record(); cd.Id = Guid.NewGuid(); cd.MainTableId = bill.Id; cd.Count = lcrv.Count; cd.CreateDate = DateTime.Now; cd.Department = bill.Department; cd.DepartmentId = bill.DepartmentId; cd.State = 1; cd.ItemBatch = lcrv.ItemBatch; cd.ItemCode = lcrv.ItemCode; cd.ItemLine = lcrv.ItemLine; cd.ItemName = lcrv.ItemName; cd.ItemSpecifications = lcrv.ItemSpecifications; cd.ItemUnit = lcrv.ItemUnit; cd.UnitWeight = lcrv.UnitWeight; cd.Weight = lcrv.Weight; cd.ItemLocation = lcrv.LocationChangeAfter; cd.ItemLocationId = lcrv.LocationChangeAfterId; cd.InOrOut = 1; cd.Warehouse = lcrv.WarehouseAfter; cd.WarehouseId = lcrv.WarehouseAfterId; cd.InOutTypeId = bill.InputTypeId; cd.InOutTypeName = bill.InputType; CurrentDBSession.RecordDal.AddEntity(cd); Record cd2 = new Record(); cd2.Id = Guid.NewGuid(); cd2.MainTableId = bill.Id; cd2.Count = lcrv.Count; cd2.CreateDate = DateTime.Now; cd2.Department = bill.Department; cd2.DepartmentId = bill.DepartmentId; cd2.State = 1; cd2.ItemBatch = lcrv.ItemBatch; cd2.ItemCode = lcrv.ItemCode; cd2.ItemLine = lcrv.ItemLine; cd2.ItemName = lcrv.ItemName; cd2.ItemSpecifications = lcrv.ItemSpecifications; cd2.ItemUnit = lcrv.ItemUnit; cd2.UnitWeight = lcrv.UnitWeight; cd2.Weight = lcrv.Weight; cd2.ItemLocation = lcrv.LocationChangeBefore; cd2.ItemLocationId = lcrv.LocationChangeBeforeId; cd2.InOrOut = 0; cd2.Warehouse = lcrv.WarehouseBefore; cd2.WarehouseId = lcrv.WarehouseBeforeId; cd2.InOutTypeId = bill.OutputTypeId; cd2.InOutTypeName = bill.OutputType; CurrentDBSession.RecordDal.AddEntity(cd2); } } //修改主表数据 CurrentDal.EditEntity(bill); } return(CurrentDBSession.SaveChanges() ? bill.Id.ToString() : "no"); }
/// <summary> /// 保存表单数据 /// </summary> /// <returns></returns> public string SaveData(TransferBill bill) { //主表id为0 新增一条记录 此时子表数据会自动插入 if (bill.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { bill.Id = Guid.NewGuid(); //生成一个id bill.BillCode = GetBillCode("ZC"); //生成单号 if (bill.BillCode == "no") { bill.BillCode = GetBillCode("ZC"); //再次生成单号 } bill.BillState = 1; //保存状态 foreach (var item in bill.Record) //生成子表id { if (item.Id == Guid.Parse("00000000-0000-0000-0000-000000000000")) { item.Id = Guid.NewGuid(); } item.CreateDate = DateTime.Now; item.State = 1; item.Warehouse = bill.Warehouse; item.WarehouseId = bill.WarehouseId; item.Department = bill.Department; item.DepartmentId = bill.DepartmentId; item.InOrOut = 1; item.InOutTypeId = bill.InputTypeId; item.InOutTypeName = bill.InputType; item.MainTableType = "TransferBill"; } CurrentDal.AddEntity(bill); } //主表有id 说明是修改的 else { //删除原子表数据 List <Record> list = CurrentDBSession.RecordDal.LoadEntities(a => a.MainTableId == bill.Id).ToList(); foreach (Record item in list) { CurrentDBSession.RecordDal.DeleteEntity(item); } //添加子表数据 foreach (Record record in bill.Record) { if (record.Id == Guid.Parse("00000000-0000-0000-0000-000000000000") || record.Id == Guid.Empty) { record.Id = Guid.NewGuid(); //设置子表id } record.MainTableId = bill.Id; //设置主表id record.CreateDate = DateTime.Now; record.State = 1; record.Warehouse = bill.Warehouse; record.WarehouseId = bill.WarehouseId; record.Department = bill.Department; record.DepartmentId = bill.DepartmentId; record.InOrOut = 1; record.InOutTypeId = bill.InputTypeId; record.InOutTypeName = bill.InputType; record.MainTableType = "TransferBill"; CurrentDBSession.RecordDal.AddEntity(record); } //修改主表数据 CurrentDal.EditEntity(bill); } //保存成功返回单据Id return(CurrentDBSession.SaveChanges() ? bill.Id.ToString() : "no"); }