/// <summary> /// 保存角色 /// </summary> /// <param name="info"></param> /// <param name="permissionIds"></param> /// <param name="keyValue"></param> public void Save(Sys_RoleInfo info, List <Sys_RoleAuthorizeInfo> permissionIds, string keyValue) { using (DbTransactionScope <Sys_RoleInfo> dbtran = base.CreateTransactionScope()) { try { //增加角色 this.InsertUpdate(info, keyValue, dbtran.Transaction); //删除角色对应权限 SearchCondition condtion = new SearchCondition(); condtion.AddCondition("F_ObjectId", info.F_Id, SqlOperator.Equal); Sys_RoleAuthorize.Instance.DeleteByCondition(condtion.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); //增加角色权限 foreach (Sys_RoleAuthorizeInfo model in permissionIds) { Sys_RoleAuthorize.Instance.Insert(model, dbtran.Transaction); } //提交事务 dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
public virtual async Task AddClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken) { ThrowIfDisposed(); Guard.ArgumentNotNull(user, nameof(user)); Guard.ArgumentNotNull(claims, nameof(claims)); if (claims.Any()) { using (DbTransactionScope scope = new DbTransactionScope()) { var ucArray = claims.Select(c => { UserClaim uc = new UserClaim(); uc.Id = _idGenerationService.GenerateId(); uc.UserId = user.Id; uc.InitializeFromClaim(c); return(uc); }).ToArray(); foreach (var u in ucArray) { await _userClaimRepository.InsertAsync(u); } scope.Complete(); } } }
/// <summary> /// 更改盘点数量 /// </summary> /// <param name="dt"></param> /// <param name="list"></param> /// <returns></returns> public string UpMaskNum(DataTable dt, List <SO_StockMakeBodyInfo> list) { using (DbTransactionScope <SO_StockMakeBodyInfo> dbtran = base.CreateTransactionScope()) { try { List <SO_StockMakeBodyInfo> bodyList = BLLFactory <SO_StockMakeBody> .Instance.GetAll(); //找出对应的数据,再进行更改 for (int i = 0; i < dt.Rows.Count; i++) { SO_StockMakeBodyInfo bodyInfo = bodyList.Find(u => u.F_Batch == dt.Rows[i]["批次"].ToString() && u.F_GoodsName == dt.Rows[i]["产品名称"].ToString() && u.F_Number == int.Parse(dt.Rows[i]["账面数量"].ToString()) && u.F_SellingPrice == decimal.Parse(dt.Rows[i]["销售价格"].ToString()) && u.F_Unit == dt.Rows[i]["单位"].ToString() && u.F_WarehouseName == dt.Rows[i]["所属仓库"].ToString() && u.F_CargoPositionName == dt.Rows[i]["所属货位"].ToString()); Hashtable hash = new Hashtable(); hash.Add("F_RealNumber", dt.Rows[i]["实盘数量"].ToString()); SO_StockMakeBody.Instance.Update(bodyInfo.F_Id, hash, dbtran.Transaction); } dbtran.Commit(); return("操作成功"); } catch (Exception) { dbtran.RollBack(); return("操作失败"); } } }
public string createCode(string F_Id) { using (DbTransactionScope <PI_ReturnHeadInfo> dbtran = base.CreateTransactionScope()) { try { SearchCondition condition = new SearchCondition(); condition.AddCondition("F_OrderDetailedId", F_Id, SqlOperator.Equal); List <PI_ReturnBodyInfo> list = PI_ReturnBody.Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); if (!string.IsNullOrEmpty(list[0].F_EnCode)) { return("生成失败,该资产已经生成条码!"); } string orderNo = "In" + DateTime.Now.ToString("yyyyMMdd"); Hashtable hash = new Hashtable(); hash.Add("Prefix", orderNo); foreach (PI_ReturnBodyInfo item in list) { DataTable dt = base.StorePorcToDataTable("SYS_CREATESN", hash, null, dbtran.Transaction); string SN = dt.Rows[0][0].ToString().PadLeft(6, '0'); item.F_EnCode = orderNo + SN; PI_ReturnBody.Instance.Update(item, dbtran.Transaction); } dbtran.Commit(); return("生成成功!"); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
/// <summary> /// 删除菜单 /// </summary> /// <param name="Id"></param> /// <returns></returns> public bool DeleteFromById(string Id) { using (DbTransactionScope <Sys_ModuleInfo> dbtran = base.CreateTransactionScope()) { try { SearchCondition search = new SearchCondition(); search.AddCondition("F_ModuleId", Id, SqlOperator.Equal); BLLFactory <Sys_ModuleButton> .Instance.DeleteByCondition(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); //找到对应的from界面 List <Sys_ModuleFormInfo> GetfromList = BLLFactory <Sys_ModuleForm> .Instance.Find(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); if (GetfromList != null)//循环删除FromInstance { foreach (var item in GetfromList) { search = new SearchCondition(); search.AddCondition("F_FormId", item.F_Id, SqlOperator.Equal); BLLFactory <Sys_ModuleFormInstance> .Instance.DeleteByCondition(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); } } ///删除from界面 BLLFactory <Sys_ModuleForm> .Instance.DeleteByCondition(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); dbtran.Commit(); return(true); } catch (Exception ex) { throw; } } }
private void DBTransactionCommitTest() { ClearDapperCompisiteKeyEntity(); var result = helper.ExecuteSQL <object>(@"DROP TABLE IF EXISTS dapper_compisite_key", command => { helper.CreateDataBaseIfNoExist("test"); helper.CreateTableIfNoExist(new[] { "dapper_compisite_key" }); var dapperRuntime = this.GetDapperRuntime(); var workContext = this.MockWorkContext(dapperRuntime); var dapperRepository = this.GetRepository <DapperCompisiteKeyEntity>(workContext); var id = 1; #region 类对象 var entity = new DapperCompisiteKeyEntity { products_id = id + 1, language_id = id + 1, products_name = (id + 1).ToString(), products_description = (id + 1).ToString(), products_short_description = (id + 1).ToString(), products_url = (id + 1).ToString(), products_viewed = id + 1 }; var entityNext = new DapperCompisiteKeyEntity { products_id = id + 2, language_id = id + 2, products_name = (id + 2).ToString(), products_description = (id + 2).ToString(), products_short_description = (id + 2).ToString(), products_url = (id + 2).ToString(), products_viewed = (id + 2) }; #endregion try { using (DbTransactionScope scope = new DbTransactionScope(workContext)) { dapperRepository.Insert(entity); using (DbTransactionScope scope2 = new DbTransactionScope(workContext)) { dapperRepository.Insert(entityNext); scope2.Complete(); } scope.Complete(); } var sql = "select count(*) from dapper_compisite_key"; command.CommandText = sql; var count = Convert.ToInt32(command.ExecuteScalar()); Assert.Equal(count, 2); } finally { ClearDapperCompisiteKeyEntity(); } return(null); }); Assert.Equal(result, null); }
public void TestNoLock() { IDataBaseHandler idb = dbctx.Handler; using (DbTransactionScope dbt = new DbTransactionScope(idb)) { Object obj = idb.ExecuteScalar("select [CompanyName] from Customers where [CustomerID] ='ANATR'"); // obj.ToString().Substring(0, obj.ToString().Length - 2) + DateTime.Now.Ticks.ToString().Substring(0, 2); String val = obj.ToString(); char[] charArray = val.ToCharArray(); Array.Reverse(charArray); val = new string(charArray);// idb.ExecuteNonQuery("update Customers set [CompanyName]='" + val + "' where [CustomerID] ='ANATR'"); IDataBaseHandler idb2 = dbctx.Handler; // idb2.ExecuteNonQuery(" SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"); obj = idb2.ExecuteScalar("select [CompanyName] from Customers where [CustomerID] ='ANATR'"); System.Console.WriteLine(obj.ToString()); DataSet ds = idb2.ExecuteQuery("select * from Customers"); System.Console.WriteLine(ds.Tables[0].Rows.Count); dbt.Complete(); } }
/// <summary> /// 保存拣货单 /// </summary> /// <param name="headInfo"></param> /// <param name="dInfo"></param> /// <returns></returns> public bool Save(PackList_HeadInfo headInfo, List <PackList_BodyInfo> dInfo) { using (DbTransactionScope <PackList_HeadInfo> dbtran = base.CreateTransactionScope()) { try { //判断当前单据是否已经审核 var head = this.FindByID(headInfo.F_Id, dbtran.Transaction); if (head != null && head.F_Status > 0) { throw new ApplicationException("单据已经审核!"); } var ID = headInfo.F_Id; Instance.InsertUpdate(headInfo, headInfo.F_Id, dbtran.Transaction); //添加主表 SearchCondition search = new SearchCondition(); //查找子表 search.AddCondition("F_HeadId", headInfo.F_Id, SqlOperator.Equal); PackList_Body.Instance.DeleteByCondition(search.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); //删除子表 PackList_Body.Instance.InsertRange(dInfo, dbtran.Transaction); //添加主表 dbtran.Commit(); return(true); } catch (Exception ex) { dbtran.RollBack(); return(false); throw; } } }
/// <summary> /// <see cref="IRepository.Insert"/> /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public int Insert(T entity) { Guard.ArgumentNotNull(entity, nameof(entity)); var segments = Context.Runtime.GetCrudSegments(EntityType); var sql = segments.InsertSql; var field = GetAutoGenerationField(); var connection = GetWritingConnection(); if (field != null) { using (var scope = new DbTransactionScope()) { var mergedSql = string.Concat(sql, ";", Environment.NewLine, DataSource.DatabaseProvider.GetLastedInsertId()); var id = connection.ExecuteScalar(mergedSql, entity); scope.Complete(); PropertySetter.SetProperty(field.Field, entity, id); return(1); } } var count = connection.Execute(sql, entity); return(count); }
/// <summary> /// 保存 /// </summary> /// <param name="info"></param> /// <param name="dInfo"></param> public void Save(SYS_BarcodeSettingMainInfo info, List <SYS_BarcodeSettingDetailInfo> dInfo) { using (DbTransactionScope <SYS_BarcodeSettingMainInfo> dbtran = base.CreateTransactionScope()) { try { //主表添加,修改 SYS_BarcodeSettingMain.Instance.InsertUpdate(info, info.F_Id, dbtran.Transaction); //子表根据主表id全删除 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_ParentId", info.F_Id, SqlOperator.Equal); BLLFactory <SYS_BarcodeSettingDetail> .Instance.DeleteByCondition(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); //添加子表 foreach (SYS_BarcodeSettingDetailInfo model in dInfo) { model.F_CreatorTime = DateTime.Now; model.F_CreatorUserId = info.F_CreatorUserId; model.F_Id = Guid.NewGuid().ToString(); model.F_ParentId = info.F_Id; SYS_BarcodeSettingDetail.Instance.Insert(model, dbtran.Transaction); } dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
public SO_StockMakeHeadInfo Save(SO_StockMakeHeadInfo info, List <SO_StockMakeBodyInfo> dInfo) { using (DbTransactionScope <SO_StockMakeHeadInfo> dbtran = base.CreateTransactionScope()) { try { DateTime time = DateTime.Now; if (string.IsNullOrEmpty(info.F_EnCode)) { string orderNo = "PD" + DateTime.Now.ToString("yyyyMMdd"); Hashtable hash = new Hashtable(); hash.Add("Prefix", orderNo); DataTable dt = base.StorePorcToDataTable("SYS_CREATESN", hash, null, dbtran.Transaction); string SN = dt.Rows[0][0].ToString().PadLeft(6, '0'); info.F_EnCode = orderNo + SN; info.F_CreatorTime = time; } else { //判断当前单据是否已经审核 var head = this.FindByID(info.F_Id, dbtran.Transaction); if (head != null && head.F_Status > 0) { throw new ApplicationException("单据已经审核!"); } } //添加主表 SO_StockMakeHead.Instance.InsertUpdate(info, info.F_Id, dbtran.Transaction); //删除子表 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_HId", info.F_Id, SqlOperator.Equal); SO_StockMakeBody.Instance.DeleteByCondition(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); //循环添加子表 foreach (SO_StockMakeBodyInfo item in dInfo) { item.F_WarehouseId = info.F_WarehouseId; item.F_CreatorTime = time; item.F_CreatorUserId = info.F_CreatorUserId; item.F_Id = Guid.NewGuid().ToString(); item.F_HId = info.F_Id; item.F_EnabledMark = false; } //添加子表 SO_StockMakeBody.Instance.InsertRange(dInfo, dbtran.Transaction); dbtran.Commit(); return(info); } catch (Exception ex) { dbtran.RollBack(); return(null); } } }
/// <summary> /// 批量删除主子表 /// </summary> /// <param name="keyValue"></param> public void DeleteBatch(string keyValue, bool bLogicDelete) { using (DbTransactionScope <Sys_VouchTypeInfo> dbtran = base.CreateTransactionScope()) { try { if (bLogicDelete) { //逻辑删除v //UPDATE字段 Hashtable hash = new Hashtable(); hash.Add("字段名", "修改后的值"); this.Update(keyValue, hash, dbtran.Transaction); //UPDATE 对象 Sys_VouchTypeInfo info = this.FindByID(keyValue, dbtran.Transaction); info.F_DeleteMark = false; info.F_DeleteTime = DateTime.Now; this.Update(info, keyValue, dbtran.Transaction); //获取所有的子表信息 SearchCondition c = new SearchCondition(); c.AddCondition("F_VouchId", keyValue, SqlOperator.Equal); List <Sys_VouchTypeDefaultInfo> details = Sys_VouchTypeDefault.Instance.Find(c.BuildConditionSql()); foreach (Sys_VouchTypeDefaultInfo d in details) { d.F_DeleteMark = false; d.F_DeleteTime = DateTime.Now; Sys_VouchTypeDefault.Instance.Update(d, d.F_Id, dbtran.Transaction); } //sql方式update //更新主表状态删除标志状态 string sql = "UPDATE Sys_VouchType SET DeleteMark =1 WHERE F_Id = @F_Id"; Hashtable parms = new Hashtable(); parms.Add("F_Id", keyValue); base.ExecuteNonQuery(sql, parms, dbtran.Transaction); //更新子表删除标志状态 sql = "UPDATE Sys_VouchTypeDefault SET DeleteMark =1 WHERE F_VouchId = @F_Id"; base.ExecuteNonQuery(sql, parms, dbtran.Transaction); } else { //物理删除 //删除 sys_VouchType this.Delete(keyValue, dbtran.Transaction); //删除 sys_VouchTypeDefault SearchCondition condition = new SearchCondition(); condition.AddCondition("F_VouchId", keyValue, SqlOperator.Equal); Sys_VouchTypeDefault.Instance.DeleteByCondition(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); } dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
/// <summary> /// 保存 /// </summary> /// <param name="model"></param> /// <param name="fromList"></param> /// <param name="fromInsList"></param> /// <param name="buttonList"></param> /// <returns></returns> public string Save(Sys_ModuleInfo model, List <Sys_ModuleFormInfo> fromList, List <Sys_ModuleFormInstanceInfo> fromInsList, List <Sys_ModuleButtonInfo> buttonList) { using (DbTransactionScope <Sys_ModuleInfo> dbtran = base.CreateTransactionScope()) { try { //添加或修改主表 BLLFactory <Sys_Module> .Instance.InsertUpdate(model, model.F_Id, dbtran.Transaction); //先删除子表再添加子表 SearchCondition search = new SearchCondition(); search.AddCondition("F_ModuleId", model.F_Id, SqlOperator.Equal); BLLFactory <Sys_ModuleButton> .Instance.DeleteByCondition(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); //找到对应的from界面 List <Sys_ModuleFormInfo> GetfromList = BLLFactory <Sys_ModuleForm> .Instance.Find(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); if (GetfromList != null)//循环删除FromInstance { foreach (var item in GetfromList) { search = new SearchCondition(); search.AddCondition("F_FormId", item.F_Id, SqlOperator.Equal); BLLFactory <Sys_ModuleFormInstance> .Instance.DeleteByCondition(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); } } ///删除from界面 BLLFactory <Sys_ModuleForm> .Instance.DeleteByCondition(search.BuildConditionSql().Replace(" Where (1=1) AND", string.Empty), dbtran.Transaction); dbtran.Commit(); //添加子表 if (fromList != null && fromList.Count > 0) { BLLFactory <Sys_ModuleForm> .Instance.InsertRange(fromList); } if (fromInsList != null && fromInsList.Count > 0) { BLLFactory <Sys_ModuleFormInstance> .Instance.InsertRange(fromInsList); } if (buttonList != null && buttonList.Count > 0) { BLLFactory <Sys_ModuleButton> .Instance.InsertRange(buttonList); } dbtran.Commit(); return("1"); } catch (Exception) { dbtran.RollBack(); throw; } } }
/// <summary> /// 更改仓库状态 /// </summary> /// <param name="Id">仓库Id</param> /// <returns></returns> public bool upEnMask(string Id) { using (DbTransactionScope <Mst_WarehouseInfo> dbtran = base.CreateTransactionScope()) { try { bool UpState = false; Mst_WarehouseInfo warehouseInfo = BLLFactory <Mst_Warehouse> .Instance.FindByID(Id); if (warehouseInfo.F_EnabledMark == true) //如果是禁用仓库,则启用仓库 { warehouseInfo.F_EnabledMark = false; } else { warehouseInfo.F_EnabledMark = true; } UpState = warehouseInfo.F_EnabledMark == true ? true : false; //将此仓库下面的货位一起禁用或者启用 List <Mst_PositionInfo> positionList = BLLFactory <Mst_Position> .Instance.GetAll(); List <Mst_PositionInfo> upList = positionList.FindAll(u => u.F_WarehouseId == Id); List <Mst_PositionInfo> parentList = positionList.FindAll(u => upList.FindAll(t => t.F_Id == u.F_ParentId) != null); foreach (var item in parentList) { if (!upList.Contains(item)) { upList.Add(item); } } foreach (var item in upList) { Hashtable has = new Hashtable(); has.Add("F_EnabledMark", UpState); BLLFactory <Mst_Position> .Instance.Update(item.F_Id, has, dbtran.Transaction); } BLLFactory <Mst_Warehouse> .Instance.Update(warehouseInfo, Id, dbtran.Transaction); dbtran.Commit(); return(true); } catch (Exception) { dbtran.RollBack(); return(false); } } }
/// <summary> /// 增加子表 /// </summary> /// <param name="info"></param> /// <param name="keyValue"></param> public void insert(SYS_BarcodeSettingDetailInfo info, string keyValue) { using (DbTransactionScope <SYS_BarcodeSettingDetailInfo> dbtran = base.CreateTransactionScope()) { try { SYS_BarcodeSettingDetail.Instance.InsertUpdate(info, keyValue, dbtran.Transaction); dbtran.Commit(); } catch (Exception) { throw; } } }
public void UpMark(string keyValue, string Name, bool State) { using (DbTransactionScope <Mst_WarehouseInfo> dbtran = base.CreateTransactionScope()) { try { Mst_WarehouseInfo info = BLLFactory <Mst_Warehouse> .Instance.FindByID(keyValue); Hashtable hash = new Hashtable(); //判断是否是仓库仓库做操作 if (Name == "F_EnabledMark") { hash.Add("F_EnabledMark", State); //如果是禁用仓库,便禁用此仓库下的货位 if (!State) { hash.Add("F_CarGoMark", State); BLLFactory <Mst_Warehouse> .Instance.Update(info.F_Id, hash, dbtran.Transaction); SearchCondition search = new SearchCondition(); search.AddCondition("F_WarehouseId", keyValue, SqlOperator.Equal); List <Mst_CargoPositionInfo> CarInfo = BLLFactory <Mst_CargoPosition> .Instance.Find(search.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty).Replace("Where (1=1)", " ( 1 = 1 ) ")); foreach (Mst_CargoPositionInfo item in CarInfo) { hash = new Hashtable(); hash.Add("F_EnabledMark", State); Mst_CargoPosition.Instance.Update(item.F_Id, hash, dbtran.Transaction); } } } else { hash.Add("F_CarGoMark", State); BLLFactory <Mst_Warehouse> .Instance.Update(info.F_Id, hash); } dbtran.Commit(); } catch (Exception) { dbtran.RollBack(); throw; } } }
/// <summary> /// 删除子表信息 /// </summary> /// <param name="keyValue"></param> public void deleteId(string keyValue) { using (DbTransactionScope <SYS_BarcodeSettingDetailInfo> dbtran = base.CreateTransactionScope()) { try { SearchCondition condition = new SearchCondition(); condition.AddCondition("F_Id", keyValue, SqlOperator.Equal); BLLFactory <SYS_BarcodeSettingDetail> .Instance.DeleteByCondition(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
public void DeleteAll(string keyValue, bool bLogicDelete = false) { using (DbTransactionScope <PI_ReturnHeadInfo> dbtran = base.CreateTransactionScope()) { try { PI_ReturnHead.Instance.Delete(keyValue, dbtran.Transaction); SearchCondition condition = new SearchCondition(); condition.AddCondition("F_HId", keyValue, SqlOperator.Equal); PI_ReturnBody.Instance.DeleteByCondition(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
/// <summary> /// 修改子表 /// </summary> /// <param name="info"></param> /// <param name="keyword"></param> /// <param name="keyValue"></param> public void insertDetail(SYS_BarcodeSettingDetailInfo info, string keyword, string keyValue) { using (DbTransactionScope <SYS_BarcodeSettingDetailInfo> dbtran = base.CreateTransactionScope()) { try { SearchCondition condition = new SearchCondition(); condition.AddCondition("F_Parent", keyword, SqlOperator.Equal); condition.AddCondition("F_Id", keyValue, SqlOperator.Equal); BLLFactory <SYS_BarcodeSettingDetail> .Instance.InsertUpdate(info, condition); dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
//保存业务类型设置 public void Save(Sys_VouchTypeInfo info, List <Sys_VouchTypeDefaultInfo> dInfo, string keyValue) { using (DbTransactionScope <Sys_VouchTypeInfo> dbtran = base.CreateTransactionScope()) { try { //主子表同时更新 //主表更新/新增 //子表根据主表id全删除 //添加子表 //增加子表 //如果是修改,先删除后增加 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_VouchId", info.F_Id, SqlOperator.Equal); BLLFactory <Sys_VouchTypeDefault> .Instance.DeleteByCondition(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty)); foreach (Sys_VouchTypeDefaultInfo model in dInfo) { //如果不选择默认值,即传入的F_EnCode为null就不插值 if (!string.IsNullOrEmpty(model.F_EnCode)) { Sys_VouchTypeDefault.Instance.Insert(model, dbtran.Transaction); } } //增加主表 this.InsertUpdate(info, keyValue, dbtran.Transaction); dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
public void Status(string F_Id, string userName) { using (DbTransactionScope <PI_HeadInfo> dbtran = base.CreateTransactionScope()) { try { //更新登记单主表审核状态,审核人,审核时间 PI_HeadInfo head = PI_Head.Instance.FindByID(F_Id, dbtran.Transaction); head.F_Status = 1; head.F_Verify = userName; head.F_VeriDate = DateTime.Now; PI_Head.Instance.Update(head, F_Id, dbtran.Transaction); //找到登记单子表 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_HId", F_Id, SqlOperator.Equal); List <PI_BodyInfo> list = PI_Body.Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); //资产编号 foreach (PI_BodyInfo item in list) { for (int i = 0; i < item.F_InStockNum; i++) { PI_BodyInfo entity = new PI_BodyInfo(); entity.F_Id = Guid.NewGuid().ToString(); entity.F_EnCode = item.F_EnCode; entity.F_FullName = item.F_FullName; entity.F_OrderNo = item.F_OrderNo; entity.F_Supplier = item.F_Supplier; entity.F_Unit = item.F_Unit; entity.F_Description = item.F_Description; PI_Body.Instance.Insert(entity, dbtran.Transaction); } } dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
public void MyTestAccess() { using (DbAccess db = DbPackage.CreateConnection()) { // ... var test1 = db.GetSampleSetting("TestDomain"); // ... var test2 = db.LoadSampleObjByAction(test1.Item1, test1.Item2); // ... using (DbTransactionScope tran = db.NewTransactionScope()) // Start a transaction { var test3 = db.LoadSampleObjByMap(test1.Item1, test1.Item2); // ... db.LogSampleError("Test source", "Test message ..."); // ... tran.Complete(); } // Exit (Commit) the transaction // ... var test4 = db.LoadSampleObjAutoMap(test1.Item1, test1.Item2); // ... } }
public void Copys(Sys_GridColumnSettingInfo Info, List <Sys_GridColumnSettingInfo> list) { using (DbTransactionScope <Sys_GridColumnSettingInfo> dbtran = base.CreateTransactionScope()) { try { //新增主表 Sys_GridColumnSetting.Instance.Insert(Info, dbtran.Transaction); //新增详细表 foreach (Sys_GridColumnSettingInfo model in list) { Sys_GridColumnSetting.Instance.Insert(model, dbtran.Transaction); } dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
public virtual async Task RemoveClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken) { ThrowIfDisposed(); Guard.ArgumentNotNull(user, nameof(user)); Guard.ArgumentNotNull(claims, nameof(claims)); SingleQueryFilter filter = new SingleQueryFilter(); filter.AddEqual(nameof(UserClaim.UserId), user.Id); var userClaims = await _userClaimRepository.QueryAsync(filter); var types = claims.Select(uc => uc.Type).ToArray(); var toRemove = userClaims.Where(c => types.Contains(c.ClaimType, StringComparer.OrdinalIgnoreCase)).ToArray(); using (DbTransactionScope scope = new DbTransactionScope()) { foreach (var u in toRemove) { await _userClaimRepository.DeleteAsync(u); } scope.Complete(); } }
/// <summary> ///审核单据 /// </summary> /// <param name="date">审核日期</param> /// <param name="Id">审核单据</param> /// <param name="user">审核人</param> public string Audit(string date, string user, string Id, List <PI_ReturnBodyInfo> stockinfo) { string SqlAuditSel = "select F_Status from PI_ReturnHead where F_Id='" + Id + "'"; string AuditState = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString(); if (AuditState == "1") { return("单据已被审核"); } else { using (DbTransactionScope <PI_ReturnHeadInfo> dbtran = base.CreateTransactionScope()) { try { Hashtable hash = new Hashtable(); //查询所有库存信息 List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll(); PI_ReturnHeadInfo hinfo = BLLFactory <PI_ReturnHead> .Instance.FindByID(Id); SearchCondition condition = new SearchCondition(); //condition.AddCondition("F_EnCode", hinfo.F_InStockCode, SqlOperator.Equal); //PI_HeadInfo pih = BLLFactory<PI_Head>.Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty))[0]; for (int i = 0; i < stockinfo.Count; i++) { //查询子表信息 condition = new SearchCondition(); condition.AddCondition("F_Id", stockinfo[i].F_Id, SqlOperator.Equal); PI_ReturnBodyInfo bodyinfo = BLLFactory <PI_ReturnBody> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty))[0]; if (bodyinfo.F_WarehouseId == "" || bodyinfo.F_CargoPositionId == "") { return("该单据中仓库或仓位为空,审核未通过"); } Sys_StockInfo stock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_WarehouseId && u.F_CargoPositionId == bodyinfo.F_CargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId && u.F_Batch == bodyinfo.F_SerialNum); //查询库存表是否存在该仓库中的产品 if (stock == null) { dbtran.RollBack(); return("该仓库无此产品"); } if (stock.F_Number - bodyinfo.F_ReturnNum < 0) { return("产品数量发生了变化,请重新选择审核退回"); } //判断库存数量是否足够 if (stock.F_Number >= bodyinfo.F_ReturnNum) { //扣减库存 hash = new Hashtable(); hash.Add("F_Number", stock.F_Number - bodyinfo.F_ReturnNum); Sys_Stock.Instance.Update(stock.F_Id, hash, dbtran.Transaction); //标记为已退货 //hash = new Hashtable(); //hash.Add("F_DocumentNum", 1); //PI_Head.Instance.Update(pih.F_Id, hash, dbtran.Transaction); //添加履历 Sys_InReturnHistoryInfo inRec = new Sys_InReturnHistoryInfo(); inRec.F_Id = Guid.NewGuid().ToString(); inRec.F_EnCode = bodyinfo.F_OrderNo; inRec.F_Batch = bodyinfo.F_SerialNum; inRec.F_Vendor = bodyinfo.F_Vendor; inRec.F_VendorName = bodyinfo.F_VendorName; inRec.F_Verify = user; inRec.F_Maker = hinfo.F_Maker; inRec.F_Contacts = hinfo.F_Contacts; inRec.F_TelePhone = hinfo.F_TelePhone; inRec.F_Address = hinfo.F_Address; inRec.F_VeriDate = DateTime.Now; inRec.F_WarehouseId = bodyinfo.F_WarehouseId; inRec.F_WarehouseName = bodyinfo.F_WarehouseName; inRec.F_GoodsName = bodyinfo.F_GoodsName; inRec.F_GoodsId = bodyinfo.F_GoodsId; inRec.F_CargoPositionId = bodyinfo.F_CargoPositionId; inRec.F_CargoPositionName = bodyinfo.F_CargoPositionName; inRec.F_SpecifModel = bodyinfo.F_SpecifModel; inRec.F_SellingPrice = bodyinfo.F_SellingPrice; inRec.F_PurchasePrice = bodyinfo.F_PurchasePrice; inRec.F_Unit = bodyinfo.F_Unit; inRec.F_InStockNum = bodyinfo.F_InStockNum; inRec.F_ReturnNum = bodyinfo.F_ReturnNum; inRec.F_CreatorTime = DateTime.Now; Sys_InReturnHistory.Instance.Insert(inRec, dbtran.Transaction); //添加库存履历 Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo(); instockHistory.F_Id = Guid.NewGuid().ToString(); instockHistory.F_EnCode = bodyinfo.F_OrderNo; instockHistory.F_Batch = bodyinfo.F_SerialNum; instockHistory.F_Vendor = hinfo.F_Vendor; instockHistory.F_VendorName = bodyinfo.F_VendorName; instockHistory.F_Verify = user; instockHistory.F_Maker = hinfo.F_Maker; instockHistory.F_Contacts = hinfo.F_Contacts; instockHistory.F_TelePhone = hinfo.F_TelePhone; instockHistory.F_Address = hinfo.F_Address; instockHistory.F_VeriDate = DateTime.Now; instockHistory.F_WarehouseId = bodyinfo.F_WarehouseId; instockHistory.F_WarehouseName = bodyinfo.F_WarehouseName; instockHistory.F_BllCategory = "入库退货"; instockHistory.F_GoodsName = bodyinfo.F_GoodsName; instockHistory.F_GoodsId = bodyinfo.F_GoodsId; instockHistory.F_CargoPositionId = bodyinfo.F_CargoPositionId; instockHistory.F_CargoPositionName = bodyinfo.F_CargoPositionName; instockHistory.F_SpecifModel = bodyinfo.F_SpecifModel; instockHistory.F_Unit = bodyinfo.F_Unit; instockHistory.F_OperationNum = 0 - bodyinfo.F_ReturnNum; instockHistory.F_CreatorTime = DateTime.Now; Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction); //更新主表入库状态 hash = new Hashtable(); hash.Add("F_State", 1); PI_ReturnHead.Instance.Update(bodyinfo.F_HId, hash, dbtran.Transaction); } else { return(bodyinfo.F_WarehouseName + "仓库库存不足,产品:" + bodyinfo.F_GoodsName + "库存为:" + stock.F_Number); } //更新审核状态 string sql = string.Format("update PI_ReturnHead set F_Status=1,F_VeriDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id); hash = new Hashtable(); base.ExecuteNonQuery(sql, hash, dbtran.Transaction); } dbtran.Commit(); return("单据审核成功"); } catch (Exception ex) { dbtran.RollBack(); return("操作失败"); throw ex; } } } }
public void Status(string F_Id, string userName, List <SO_StockMakeBodyInfo> info) { using (DbTransactionScope <SO_StockMakeHeadInfo> dbtran = base.CreateTransactionScope()) { DateTime time = DateTime.Now; try { //更新登记单主表审核状态,审核人,审核时间 SO_StockMakeHeadInfo head = SO_StockMakeHead.Instance.FindByID(F_Id, dbtran.Transaction); head.F_Status = 1; head.F_Verify = userName; head.F_VeriDate = DateTime.Now.ToShortDateString(); SO_StockMakeHead.Instance.Update(head, F_Id, dbtran.Transaction); //查询所有库存 List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll(); //库存更新履历 List <Sys_StockHistoryInfo> StockHisList = new List <Sys_StockHistoryInfo>(); //添加盘点履历 List <Sys_StockMaskHistoryInfo> list = new List <Sys_StockMaskHistoryInfo>(); //更新产品库存 foreach (SO_StockMakeBodyInfo item in info) { Sys_StockInfo Info = StockList.Find(u => u.F_WarehouseId == item.F_WarehouseId && u.F_CargoPositionId == item.F_CargoPositionId && u.F_GoodsId == item.F_GoodsId); Hashtable hash = new Hashtable(); hash.Add("F_Number", item.F_RealNumber); Sys_Stock.Instance.Update(Info.F_Id, hash, dbtran.Transaction); //添加盘点履历 Sys_StockMaskHistoryInfo maskInfo = new Sys_StockMaskHistoryInfo(); maskInfo.F_GoodsId = item.F_GoodsId; maskInfo.F_GoodsName = item.F_GoodsName; maskInfo.F_WarehouseId = item.F_WarehouseId; maskInfo.F_WarehouseName = item.F_WarehouseName; maskInfo.F_CargoPositionId = item.F_CargoPositionId; maskInfo.F_CargoPositionName = item.F_CargoPositionName; maskInfo.F_Unit = item.F_Unit; maskInfo.F_Batch = item.F_Batch; maskInfo.F_Date = time; maskInfo.F_Description = item.F_Description; maskInfo.F_EnCode = head.F_EnCode; maskInfo.F_Number = item.F_Number; maskInfo.F_RealNumber = int.Parse(item.F_RealNumber); maskInfo.F_Unit = item.F_Unit; maskInfo.F_DiffNumber = Math.Abs(int.Parse(item.F_RealNumber) - item.F_Number); list.Add(maskInfo); //添加库存信息 Sys_StockHistoryInfo HistoryInfo = new Sys_StockHistoryInfo(); HistoryInfo.F_CargoPositionId = item.F_CargoPositionId; HistoryInfo.F_CargoPositionName = item.F_CargoPositionName; HistoryInfo.F_WarehouseId = item.F_WarehouseId; HistoryInfo.F_WarehouseName = item.F_WarehouseName; HistoryInfo.F_EnCode = head.F_EnCode; HistoryInfo.F_Batch = item.F_Batch; HistoryInfo.F_BllCategory = "盘点"; HistoryInfo.F_OperationNum = int.Parse(item.F_RealNumber) - item.F_Number; HistoryInfo.F_SpecifModel = item.F_SpecifModel; HistoryInfo.F_Vendor = userName; HistoryInfo.F_GoodsId = item.F_GoodsId; HistoryInfo.F_GoodsName = item.F_GoodsName; HistoryInfo.F_Unit = item.F_Unit; //HistoryInfo.F_VendorName = head.; //HistoryInfo.F_Contacts = head.F_Contacts; //HistoryInfo.F_TelePhone = head.F_TelePhone; HistoryInfo.F_Maker = head.F_Operator; HistoryInfo.F_Verify = head.F_Verify; StockHisList.Add(HistoryInfo); } Sys_StockHistory.Instance.InsertRange(StockHisList, dbtran.Transaction); //添盘点记录 Sys_StockMaskHistory.Instance.InsertRange(list, dbtran.Transaction); dbtran.Commit(); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
/// <summary> ///审核单据 /// </summary> /// <param name="date">审核日期</param> /// <param name="Id">审核单据</param> /// <param name="user">审核人</param> public string Audit(string date, string user, string Id, List <Allocation_BodyInfo> DbInfo) { string SqlAuditSel = "select F_Status from Allocation_Head where F_Id='" + Id + "'"; string AuditState = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString(); if (AuditState == "1") { return("单据已被审核"); } else { using (DbTransactionScope <Allocation_HeadInfo> dbtran = base.CreateTransactionScope()) { try { Hashtable hash = new Hashtable(); List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll(); //查询主表信息 Allocation_HeadInfo hinfo = BLLFactory <Allocation_Head> .Instance.FindByID(Id); for (int i = 0; i < DbInfo.Count; i++) { //查询子表信息 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_Id", DbInfo[i].F_Id, SqlOperator.Equal); Allocation_BodyInfo bodyinfo = BLLFactory <Allocation_Body> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty))[0]; //判断是否出库 if (bodyinfo.F_FreeTerm1 == "") //F_FreeTerm1--0未出库 1已出库 { bodyinfo.F_FreeTerm1 = "0"; } if (int.Parse(bodyinfo.F_FreeTerm1) > 0) { return("该单据已出库,不能重复执行出库操作"); } if (bodyinfo.F_OutWareId == "" || bodyinfo.F_OutCargoPositionId == "" || bodyinfo.F_InWareId == "" || bodyinfo.F_InCargoPositionId == "") { return("该单据中仓库或仓位为空,审核未通过"); } //查询库存表是否存在该仓库中的产品 Sys_StockInfo stock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_OutWareId && u.F_CargoPositionId == bodyinfo.F_OutCargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId && u.F_Batch == bodyinfo.F_SerialNum); if (stock == null) { dbtran.RollBack(); return("该仓库无此产品"); } //判断库存数量是否足够 if (stock.F_Number > bodyinfo.F_DbNum) { //扣减库存 hash = new Hashtable(); hash.Add("F_Number", stock.F_Number - bodyinfo.F_DbNum); Sys_Stock.Instance.Update(stock.F_Id, hash, dbtran.Transaction); //添加库存履历 Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo(); instockHistory.F_Id = Guid.NewGuid().ToString(); instockHistory.F_WarehouseId = bodyinfo.F_OutWareId; instockHistory.F_EnCode = bodyinfo.F_OrderNo; instockHistory.F_Batch = bodyinfo.F_SerialNum; instockHistory.F_Verify = user; instockHistory.F_Maker = hinfo.F_Maker; instockHistory.F_VeriDate = DateTime.Now; instockHistory.F_WarehouseName = bodyinfo.F_OutWareName; instockHistory.F_BllCategory = "调出"; instockHistory.F_GoodsName = bodyinfo.F_GoodsName; instockHistory.F_GoodsId = bodyinfo.F_GoodsId; instockHistory.F_CargoPositionId = bodyinfo.F_OutCargoPositionId; instockHistory.F_CargoPositionName = bodyinfo.F_OutCargoPositionName; instockHistory.F_SpecifModel = bodyinfo.F_SpecifModel; instockHistory.F_Unit = bodyinfo.F_Unit; instockHistory.F_OperationNum = 0 - bodyinfo.F_DbNum; instockHistory.F_CreatorTime = DateTime.Now; Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction); //更新出库状态 hash = new Hashtable(); hash.Add("F_FreeTerm1", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); } else { return(bodyinfo.F_OutWareName + "仓库库存不足,当前产品" + bodyinfo.F_GoodsName + "库存为" + stock.F_Number); } Sys_StockInfo instock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_InWareId && u.F_CargoPositionId == bodyinfo.F_InCargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId); //如果不存在 if (instock == null) { //新添加一条数据 Sys_StockInfo entity = new Sys_StockInfo(); entity.F_Id = Guid.NewGuid().ToString(); entity.F_GoodsId = bodyinfo.F_GoodsId; entity.F_GoodsName = bodyinfo.F_GoodsName; entity.F_WarehouseId = bodyinfo.F_InWareId; entity.F_WarehouseName = bodyinfo.F_InWareName; entity.F_CargoPositionId = bodyinfo.F_InCargoPositionId; entity.F_CargoPositionName = bodyinfo.F_InCargoPositionName; entity.F_Batch = bodyinfo.F_SerialNum; entity.F_Unit = bodyinfo.F_Unit; entity.F_Number = bodyinfo.F_DbNum; Sys_Stock.Instance.Insert(entity, dbtran.Transaction); //添加履历 Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo(); Dbinfo.F_Id = Guid.NewGuid().ToString(); Dbinfo.F_GoodsId = bodyinfo.F_GoodsId; Dbinfo.F_InWareName = bodyinfo.F_InWareName; Dbinfo.F_EnCode = bodyinfo.F_OrderNo; Dbinfo.F_Batch = bodyinfo.F_SerialNum; Dbinfo.F_GoodsName = bodyinfo.F_GoodsName; Dbinfo.F_Verify = user; Dbinfo.F_Maker = hinfo.F_Maker; Dbinfo.F_VeriDate = DateTime.Now; Dbinfo.F_OutWareId = bodyinfo.F_OutWareId; Dbinfo.F_InWareId = bodyinfo.F_InWareId; Dbinfo.F_OutWareName = bodyinfo.F_OutWareName; Dbinfo.F_InCargoPositionId = bodyinfo.F_InCargoPositionId; Dbinfo.F_InCargoPositionName = bodyinfo.F_InCargoPositionName; Dbinfo.F_OutCargoPositionId = bodyinfo.F_OutCargoPositionId; Dbinfo.F_OutCargoPositionName = bodyinfo.F_OutCargoPositionName; Dbinfo.F_Unit = bodyinfo.F_Unit; Dbinfo.F_DBNum = bodyinfo.F_DbNum; Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel; Dbinfo.F_CreatorTime = DateTime.Now; Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction); //添加库存履历 Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo(); instockHistory.F_Id = Guid.NewGuid().ToString(); instockHistory.F_WarehouseId = bodyinfo.F_OutWareId; instockHistory.F_EnCode = bodyinfo.F_OrderNo; instockHistory.F_Batch = bodyinfo.F_SerialNum; instockHistory.F_Verify = user; instockHistory.F_Maker = hinfo.F_Maker; instockHistory.F_VeriDate = DateTime.Now; instockHistory.F_WarehouseName = bodyinfo.F_InWareName; instockHistory.F_BllCategory = "调入"; instockHistory.F_GoodsName = bodyinfo.F_GoodsName; instockHistory.F_GoodsId = bodyinfo.F_GoodsId; instockHistory.F_CargoPositionId = bodyinfo.F_InCargoPositionName; instockHistory.F_CargoPositionName = bodyinfo.F_InCargoPositionId; instockHistory.F_SpecifModel = bodyinfo.F_SpecifModel; instockHistory.F_Unit = bodyinfo.F_Unit; instockHistory.F_OperationNum = bodyinfo.F_DbNum; instockHistory.F_CreatorTime = DateTime.Now; Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction); //更新入库状态 hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); } //如果存在 else { //增加库存 hash = new Hashtable(); hash.Add("F_Number", instock.F_Number + bodyinfo.F_DbNum); Sys_Stock.Instance.Update(instock.F_Id, hash, dbtran.Transaction); //更新入库状态 hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); //添加履历 Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo(); Dbinfo.F_Id = Guid.NewGuid().ToString(); Dbinfo.F_GoodsId = bodyinfo.F_GoodsId; Dbinfo.F_Verify = user; Dbinfo.F_Maker = hinfo.F_Maker; Dbinfo.F_VeriDate = DateTime.Now; Dbinfo.F_EnCode = bodyinfo.F_OrderNo; Dbinfo.F_Batch = bodyinfo.F_SerialNum; Dbinfo.F_InWareName = bodyinfo.F_InWareName; Dbinfo.F_GoodsName = bodyinfo.F_GoodsName; Dbinfo.F_OutWareId = bodyinfo.F_OutWareId; Dbinfo.F_InWareId = bodyinfo.F_InWareId; Dbinfo.F_OutWareName = bodyinfo.F_OutWareName; Dbinfo.F_InCargoPositionId = bodyinfo.F_InCargoPositionId; Dbinfo.F_InCargoPositionName = bodyinfo.F_InCargoPositionName; Dbinfo.F_OutCargoPositionId = bodyinfo.F_OutCargoPositionId; Dbinfo.F_OutCargoPositionName = bodyinfo.F_OutCargoPositionName; Dbinfo.F_Unit = bodyinfo.F_Unit; Dbinfo.F_DBNum = bodyinfo.F_DbNum; Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel; Dbinfo.F_CreatorTime = DateTime.Now; Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction); //添加库存履历 Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo(); instockHistory.F_Id = Guid.NewGuid().ToString(); instockHistory.F_WarehouseId = bodyinfo.F_InWareId; instockHistory.F_WarehouseName = bodyinfo.F_InWareName; instockHistory.F_EnCode = bodyinfo.F_OrderNo; instockHistory.F_Batch = bodyinfo.F_SerialNum; instockHistory.F_Verify = user; instockHistory.F_Maker = hinfo.F_Maker; instockHistory.F_VeriDate = DateTime.Now; instockHistory.F_BllCategory = "调入"; instockHistory.F_GoodsName = bodyinfo.F_GoodsName; instockHistory.F_GoodsId = bodyinfo.F_GoodsId; instockHistory.F_CargoPositionId = bodyinfo.F_InCargoPositionId; instockHistory.F_CargoPositionName = bodyinfo.F_InCargoPositionName; instockHistory.F_SpecifModel = bodyinfo.F_SpecifModel; instockHistory.F_Unit = bodyinfo.F_Unit; instockHistory.F_OperationNum = bodyinfo.F_DbNum; instockHistory.F_CreatorTime = DateTime.Now; Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction); } } //更新审核状态 string sql = string.Format("update Allocation_Head set F_Status=1,F_AccountDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id); hash = new Hashtable(); base.ExecuteNonQuery(sql, hash, dbtran.Transaction); dbtran.Commit(); return("单据审核成功"); } catch (Exception ex) { dbtran.RollBack(); return("操作失败"); throw ex; } } } }
public OutStockNotice_HeadInfo Save(OutStockNotice_HeadInfo info, List <OutStockNotice_BodyInfo> BInfo) { using (DbTransactionScope <OutStockNotice_HeadInfo> dbtran = base.CreateTransactionScope()) { try { if (string.IsNullOrEmpty(info.F_EnCode)) { string orderNo = "OUTOT" + DateTime.Now.ToString("yyyyMMdd"); Hashtable hash = new Hashtable(); hash.Add("Prefix", orderNo); DataTable dt = base.StorePorcToDataTable("SYS_GENERATE_SN", hash, null, dbtran.Transaction); string SN = dt.Rows[0][0].ToString(); info.F_EnCode = SN; } else { //判断当前单据是否已经审核 var head = this.FindByID(info.F_Id, dbtran.Transaction); if (head != null && head.F_Status == 1) { throw new ApplicationException("单据已经审核!"); } } info.F_Status = 0; info.F_Verifier = ""; info.F_Veridate = null; //添加主表 OutStockNotice_Head.Instance.InsertUpdate(info, info.F_Id, dbtran.Transaction); //删除子表 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_HeadId", info.F_Id, SqlOperator.Equal); OutStockNotice_Body.Instance.DeleteByCondition(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty), dbtran.Transaction); //循环添加子表 foreach (OutStockNotice_BodyInfo item in BInfo) { item.F_CreatorTime = DateTime.Now; item.F_CreatorUserId = info.F_CreatorUserId; item.F_Id = Guid.NewGuid().ToString(); item.F_HeadId = info.F_Id; string orderNo = "OUTOTOTB" + DateTime.Now.ToString("yyyyMMdd"); Hashtable hash = new Hashtable(); hash.Add("Prefix", orderNo); DataTable dt = base.StorePorcToDataTable("SYS_GENERATE_SN", hash, null, dbtran.Transaction); string SN = dt.Rows[0][0].ToString(); item.F_EnCode = SN; //OutStockNotice_Body.Instance.Insert(item, dbtran.Transaction); } OutStockNotice_Body.Instance.InsertRange(BInfo, dbtran.Transaction); dbtran.Commit(); return(info); } catch (Exception ex) { dbtran.RollBack(); throw ex; } } }
public string SaveTra(Sys_TransferInfo info) { try { using (DbTransactionScope <Sys_TransferInfo> dbtran = base.CreateTransactionScope()) { int JNum = int.Parse(info.F_Number) - int.Parse(info.F_TransferNum); if (JNum < 0) { return("该产品数量不足"); } else { //减少库存数量 Hashtable has = new Hashtable(); this.ExecuteNonQuery(string.Format("update Sys_Stock set F_Number='{0}' where F_Id='{1}'", JNum, info.F_StockId), has); //判断转移的货位是否存在此产品 string SelGoods = string.Format("select * from Sys_Stock where F_GoodsId='{0}' and F_WarehouseId='{1}' and F_CargoPositionId='{2}'", info.F_GoodsId, info.F_TransferWarHouseId, info.F_TransferCargoId); int count = this.GetDataTableBySql(SelGoods).Rows.Count; if (count > 0) { //存在则添加库存 Hashtable hash = new Hashtable(); string UpStockGoodsNum = string.Format("update Sys_Stock set F_Number=F_Number+{0} where F_GoodsId='{1}' and F_WarehouseId='{2}' and F_CargoPositionId='{3}'", info.F_TransferNum, info.F_GoodsId, info.F_TransferWarHouseId, info.F_TransferCargoId); this.ExecuteNonQuery(UpStockGoodsNum); // 添加物品转移履历 Sys_Transfer.Instance.Insert(info); } else { //获取产品信息 DataTable dt = this.GetDataTableBySql("select F_Batch,F_ProDate,F_ExpiratDate,F_CategoryID,F_Unit,F_SellingPrice from Sys_Stock where F_Id='" + info.F_StockId + "'"); //否则添加产品 Sys_StockInfo StockInfo = new Sys_StockInfo(); StockInfo.F_Number = int.Parse(info.F_TransferNum); StockInfo.F_WarehouseId = info.F_TransferWarHouseId; StockInfo.F_WarehouseName = info.F_TransferWarHouse; StockInfo.F_GoodsId = info.F_GoodsId; StockInfo.F_GoodsName = info.F_GoodsName; StockInfo.F_CargoPositionId = info.F_TransferCargoId; StockInfo.F_CargoPositionName = info.F_TransferCargo; StockInfo.F_EnCode = info.F_EnCode; StockInfo.F_Batch = dt.Rows[0][0].ToString(); StockInfo.F_ProDate = dt.Rows[0][1].ToString(); StockInfo.F_ExpiratDate = dt.Rows[0][2].ToString(); StockInfo.F_CategoryID = dt.Rows[0][3].ToString(); StockInfo.F_Unit = dt.Rows[0][4].ToString(); StockInfo.F_SellingPrice = dt.Rows[0][5].ToString(); StockInfo.F_CreatorTime = DateTime.Now; StockInfo.F_CreatorUserId = info.F_CreatorUserId; BLLFactory <Sys_Stock> .Instance.Insert(StockInfo); //添加物品转移履历 Sys_Transfer.Instance.Insert(info); } } return("转移成功"); } } catch (Exception ex) { return(ex.ToString()); } }
/// <summary> /// 产品入库操作 /// </summary> /// <param name="Batch"></param> /// <param name="stockinfo"></param> /// <returns></returns> public string InStock(string Batch, List <PI_BodyInfo> stockinfo) { using (DbTransactionScope <PI_BodyInfo> dbtran = base.CreateTransactionScope()) { try { //查询入库单是否审核 string SqlAuditSel = "select F_Status from PI_Head where F_Id='" + stockinfo[0].F_HId + "'"; string AuditState = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString(); if (AuditState == "0") { return("该入库单未审核,不能进行入库操作"); } //查询库存表是否存在该仓库中的产品 foreach (PI_BodyInfo item in stockinfo) { SearchCondition condtion = new SearchCondition(); condtion.AddCondition("F_GoodsId", item.F_GoodsId, SqlOperator.Equal); condtion.AddCondition("F_WarehouseId", item.F_WarehouseId, SqlOperator.Equal); List <Sys_StockInfo> stock = BLLFactory <Sys_Stock> .Instance.Find(condtion.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty)); if (stock == null) { item.IsHave = false; } else { item.IsHave = true; item.StockID = stock[0].F_Id; item.StockNumber = stock[0].F_Number; } } foreach (PI_BodyInfo item in stockinfo) { //判断是否入库 PI_BodyInfo binfo = BLLFactory <PI_Body> .Instance.FindByID(item.F_Id); if (binfo.F_AlreadyOperatedNum == "") { binfo.F_AlreadyOperatedNum = "0"; } if (int.Parse(binfo.F_AlreadyOperatedNum) > 0) { return("该单据已入库,不能重复执行入库操作"); } //查询库存表是否存在该仓库中的产品 //没有 if (!item.IsHave) { //新添加一条数据 Sys_StockInfo entity = new Sys_StockInfo(); entity.F_Id = Guid.NewGuid().ToString(); entity.F_Batch = item.F_OrderNo; entity.F_CargoPositionId = item.F_CargoPositionId; entity.F_CargoPositionName = item.F_CargoPositionName; entity.F_WarehouseId = item.F_WarehouseId; entity.F_WarehouseName = item.F_WarehouseName; entity.F_GoodsName = item.F_GoodsName; entity.F_GoodsId = item.F_GoodsId; entity.F_SpecifModel = item.F_SpecifModel; entity.F_SellingPrice = item.F_SellingPrice; entity.F_PurchasePrice = item.F_PurchasePrice; entity.F_Unit = item.F_Unit; entity.F_Number = item.F_InStockNum; Sys_Stock.Instance.Insert(entity, dbtran.Transaction); //添加履历 Sys_InRecordsInfo inRec = new Sys_InRecordsInfo(); inRec.F_Id = Guid.NewGuid().ToString(); inRec.F_WarehouseId = item.F_WarehouseId; inRec.F_WarehouseName = item.F_WarehouseName; inRec.F_GoodsName = item.F_GoodsName; inRec.F_GoodsId = item.F_GoodsId; inRec.F_CargoPositionId = item.F_CargoPositionId; inRec.F_CargoPositionName = item.F_CargoPositionName; inRec.F_SpecifModel = item.F_SpecifModel; inRec.F_SellingPrice = item.F_SellingPrice; inRec.F_PurchasePrice = item.F_PurchasePrice; inRec.F_Unit = item.F_Unit; inRec.F_InStockNum = item.F_InStockNum; inRec.F_CreatorTime = DateTime.Now; Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction); //更新子表入库状态 Hashtable hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); PI_Body.Instance.Update(item.F_Id, hash, dbtran.Transaction); //更新主表入库状态 hash = new Hashtable(); hash.Add("F_State", 1); PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction); } else { //更新前库存数量 Hashtable hash = new Hashtable(); hash.Add("F_Number", item.StockNumber + item.F_InStockNum); Sys_Stock.Instance.Update(item.StockID, hash, dbtran.Transaction); for (int i = 0; i < stockinfo.Count; i++) { if (stockinfo[i].StockID == item.StockID) { stockinfo[i].StockNumber += item.F_InStockNum; } } //更新子表入库状态 hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); PI_Body.Instance.Update(item.F_Id, hash, dbtran.Transaction); //更新主表入库状态 hash = new Hashtable(); hash.Add("F_State", 1); PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction); //添加履历 Sys_InRecordsInfo inRec = new Sys_InRecordsInfo(); inRec.F_Id = Guid.NewGuid().ToString(); inRec.F_WarehouseId = item.F_WarehouseId; inRec.F_WarehouseName = item.F_WarehouseName; inRec.F_GoodsName = item.F_GoodsName; inRec.F_GoodsId = item.F_GoodsId; inRec.F_CargoPositionId = item.F_CargoPositionId; inRec.F_CargoPositionName = item.F_CargoPositionName; inRec.F_SpecifModel = item.F_SpecifModel; inRec.F_SellingPrice = item.F_SellingPrice; inRec.F_PurchasePrice = item.F_PurchasePrice; inRec.F_Unit = item.F_Unit; inRec.F_InStockNum = item.F_InStockNum; inRec.F_CreatorTime = DateTime.Now; Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction); } } dbtran.Commit(); return("操作成功"); } catch (Exception ex) { dbtran.RollBack(); return("操作失败"); throw ex; } } //try //{ // //循环获取子表信息 // for (int i = 0; i < stockinfo.Count; i++) // { // string SqlAuditSel = "select F_Status from PI_Head where F_Id='" + stockinfo[i].F_HId + "'"; // string AuditState = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString(); // if (AuditState == "0") // { // return "该入库单未审核,不能进行入库操作"; // } // string state = "select F_AlreadyOperatedNum from PI_Body where F_Id='" + stockinfo[i].F_Id + "'"; // DataTable dt = this.GetDataTableBySql(state); // //判断是否已入库 // string AoNum = dt.Rows[0][0].ToString(); // if (AoNum == "") // { // AoNum = "0"; // } // if (int.Parse(AoNum) > 0) // { // return "该单据已入库,不能重复执行入库操作"; // } // //查询库存表是否存在该仓库中的产品 // string sql = "select F_Id,F_Number from Sys_Stock where F_GoodsId='" + stockinfo[i].F_GoodsId + "' and F_WarehouseId='" + stockinfo[i].F_WarehouseId + "'"; // //如果没有则添加一条数据 // if (this.GetDataTableBySql(sql).Rows.Count == 0) // { // //新添加一条数据 // Sys_StockInfo entity = new Sys_StockInfo(); // entity.F_Id = Guid.NewGuid().ToString(); // entity.F_Batch = stockinfo[i].F_OrderNo; // entity.F_CargoPositionId = stockinfo[i].F_CargoPositionId; // entity.F_CargoPositionName = stockinfo[i].F_CargoPositionName; // entity.F_WarehouseId = stockinfo[i].F_WarehouseId; // entity.F_WarehouseName = stockinfo[i].F_WarehouseName; // entity.F_GoodsName = stockinfo[i].F_GoodsName; // entity.F_GoodsId = stockinfo[i].F_GoodsId; // entity.F_SpecifModel = stockinfo[i].F_SpecifModel; // entity.F_SellingPrice = stockinfo[i].F_SellingPrice; // entity.F_PurchasePrice = stockinfo[i].F_PurchasePrice; // entity.F_Unit = stockinfo[i].F_Unit; // entity.F_Number = stockinfo[i].F_InStockNum; // Sys_Stock.Instance.Insert(entity); // //添加履历 // Sys_InRecordsInfo inRec = new Sys_InRecordsInfo(); // inRec.F_Id = Guid.NewGuid().ToString(); // inRec.F_WarehouseId = stockinfo[i].F_WarehouseId; // inRec.F_WarehouseName = stockinfo[i].F_WarehouseName; // inRec.F_GoodsName = stockinfo[i].F_GoodsName; // inRec.F_GoodsId = stockinfo[i].F_GoodsId; // inRec.F_CargoPositionId = stockinfo[i].F_CargoPositionId; // inRec.F_CargoPositionName = stockinfo[i].F_CargoPositionName; // inRec.F_SpecifModel = stockinfo[i].F_SpecifModel; // inRec.F_SellingPrice = stockinfo[i].F_SellingPrice; // inRec.F_PurchasePrice = stockinfo[i].F_PurchasePrice; // inRec.F_Unit = stockinfo[i].F_Unit; // inRec.F_InStockNum = stockinfo[i].F_InStockNum; // inRec.F_CreatorTime = DateTime.Now; // Sys_InRecords.Instance.Insert(inRec); // //更新子表入库状态 // string upState = "update PI_Body set F_AlreadyOperatedNum='1' where F_Id='" + stockinfo[i].F_Id + "'"; // Hashtable hash = new Hashtable(); // base.ExecuteNonQuery(upState, hash); // //更新主表入库状态 // string upStateH = "update PI_Head set F_State='1' where F_Id='" + stockinfo[i].F_HId + "'"; // Hashtable hash1 = new Hashtable(); // base.ExecuteNonQuery(upStateH, hash1); // } // //存在就更新库存 // else // { // //更新前库存数量 // int oldnum = int.Parse(this.GetDataTableBySql(sql).Rows[0][1].ToString()); // //要入库的数量 // int instockNum = stockinfo[i].F_InStockNum; // //更新后库存数量 // int num = oldnum + instockNum; // string Str = "update Sys_Stock set F_Number='" + num + "' where F_Id='" + this.GetDataTableBySql(sql).Rows[0][0].ToString() + "'"; // Hashtable hash = new Hashtable(); // base.ExecuteNonQuery(Str, hash); // //更新子表入库状态 // string upState = "update PI_Body set F_AlreadyOperatedNum='1' where F_Id='" + stockinfo[i].F_Id + "'"; // Hashtable hash1 = new Hashtable(); // base.ExecuteNonQuery(upState, hash1); // //更新主表入库状态 // string upStateH = "update PI_Head set F_State='1' where F_Id='" + stockinfo[i].F_HId + "'"; // Hashtable hash2 = new Hashtable(); // base.ExecuteNonQuery(upStateH, hash2); // //添加履历 // Sys_InRecordsInfo inRec = new Sys_InRecordsInfo(); // inRec.F_Id = Guid.NewGuid().ToString(); // inRec.F_WarehouseId = stockinfo[i].F_WarehouseId; // inRec.F_WarehouseName = stockinfo[i].F_WarehouseName; // inRec.F_GoodsName = stockinfo[i].F_GoodsName; // inRec.F_GoodsId = stockinfo[i].F_GoodsId; // inRec.F_CargoPositionId = stockinfo[i].F_CargoPositionId; // inRec.F_CargoPositionName = stockinfo[i].F_CargoPositionName; // inRec.F_SpecifModel = stockinfo[i].F_SpecifModel; // inRec.F_SellingPrice = stockinfo[i].F_SellingPrice; // inRec.F_PurchasePrice = stockinfo[i].F_PurchasePrice; // inRec.F_Unit = stockinfo[i].F_Unit; // inRec.F_InStockNum = stockinfo[i].F_InStockNum; // inRec.F_CreatorTime = DateTime.Now; // Sys_InRecords.Instance.Insert(inRec); // } // } // return "操作成功"; //} //catch (Exception ex) //{ // throw ex; //} }