public void DeleteDept(Dept dept) { try { conn = ConnectionPool.BorrowConnection(); trans = conn.BeginTransaction(); EntityMapping.Delete(dept, trans); trans.Commit(); } catch (BusinessException bex) //业务异常 { //LogAdapter.WriteBusinessException(bex); trans.Rollback(); throw new BusinessException(bex.Type, bex.Message); } catch (SqlException sex) //数据库异常 { //事务回滚 trans.Rollback(); //LogAdapter.WriteDatabaseException(sex); throw new BusinessException("数据库异常", sex.Message); } catch (Exception ex) //其他异常 { //事务回滚 trans.Rollback(); //LogAdapter.WriteFeaturesException(ex); throw new BusinessException("其它异常", ex.Message); } finally { ConnectionPool.ReturnConnection(conn); } }
private void SyncGoods(Entity.Inventory inv, SqlTransaction trans) { //string strsql = "SELECT * FROM tbProductClass where cnvcproductclasscode='"+inv.cnvcInvCCode+"'"; //DataTable dtpc = SqlHelper.ExecuteDataTable(trans,CommandType.Text,strsql); // if(dtpc.Rows.Count>0) // { //Entity.ProductClass pc = new ProductClass(dtpc); // if(pc.cnvcProductType == "FINALPRODUCT") // { string strsql = "select * from tbGoods where vcGoodsID='" + inv.cnvcInvCode + "'"; DataTable dtGoods = SqlHelper.ExecuteDataTable(trans, CommandType.Text, strsql); if (inv.cnbSale) { if (dtGoods.Rows.Count == 0) { Entity.Goods gs = new Goods(); gs.vcGoodsID = inv.cnvcInvCode; gs.vcGoodsName = inv.cnvcInvName; gs.vcSpell = Helper.GetChineseSpell(inv.cnvcInvName); gs.nPrice = Convert.ToDecimal(inv.cnfRetailPrice); gs.nRate = 0; gs.iIgValue = -1; gs.cNewFlag = "0"; gs.vcComments = "存货档案添加同步"; EntityMapping.Create(gs, trans); } else { Entity.Goods gs = new Goods(dtGoods); if (gs.vcGoodsName != inv.cnvcInvName) { gs.vcGoodsName = inv.cnvcInvName; gs.vcSpell = Helper.GetChineseSpell(inv.cnvcInvName); } if (inv.cnfRetailPrice > 0) { gs.nPrice = Convert.ToDecimal(inv.cnfRetailPrice); } gs.vcComments = "存货档案修改同步"; EntityMapping.Update(gs, trans); } } else { if (dtGoods.Rows.Count > 0) { Entity.Goods gs = new Goods(dtGoods); EntityMapping.Delete(gs, trans); } } //} //} }
public void AdjustCheckSerial_Delete(CheckSerial CheckSerial, OperLog operLog) //,BusiLog busiLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); CheckSerial oldCheckSerial = EntityMapping.Get(CheckSerial, trans) as CheckSerial; if (oldCheckSerial == null) { throw new Exception("未找到对应盘点流水的产品!"); } oldCheckSerial.cnnReduceCount = CheckSerial.cnnReduceCount; oldCheckSerial.cnvcOperID = operLog.cnvcOperID; oldCheckSerial.cndOperDate = dtSysTime; EntityMapping.Delete(oldCheckSerial, trans); CheckSerialLog checkSerialLog = new CheckSerialLog(oldCheckSerial.ToTable()); checkSerialLog.cnnCheckSerialNo = oldCheckSerial.cnnSerialNo; EntityMapping.Create(checkSerialLog, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "盘点删除,盘点流水:" + oldCheckSerial.cnnSerialNo.ToString() + ",产品编码:" + CheckSerial.cnvcCode; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
public int DeleteComputationUnit(OperLog operLog, Entity.ComputationUnit cu) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); Entity.ComputationUnit oldcu = new Entity.ComputationUnit(); oldcu.cnvcComunitCode = cu.cnvcComunitCode; oldcu = EntityMapping.Get(oldcu, trans) as Entity.ComputationUnit; if (oldcu == null) { throw new Exception("未找到记录单位"); } if (oldcu.cnbMainUnit) { throw new Exception("主计量单位不能删除"); } EntityMapping.Delete(oldcu, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "计量单位组编码:" + cu.cnvcComunitCode; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); return(-1); } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); return(-1); } finally { ConnectionPool.ReturnConnection(conn); } return(1); } }
public static void DeleteOper(Oper oldOper, Oper oper) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); EntityMapping.Delete(oldOper, trans); SqlHelper.ExecuteNonQuery(trans, CommandType.Text, "delete from tbOperFunc where cnvcOperID='" + oldOper.cnvcOperID + "'"); BusiLog busiLog = new BusiLog(); busiLog.cndOperDate = dtSysTime; busiLog.cnnBusiSerialNo = Helper.GetSerialNo(trans); busiLog.cnvcComments = oldOper.cnvcOperName; busiLog.cnvcFuncCode = " 删除用户"; busiLog.cnvcOperID = oper.cnvcOperID; busiLog.cnvcIPAddress = ""; EntityMapping.Create(busiLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
public int DeleteComputationGroup(OperLog operLog, ComputationGroup cg) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); ComputationGroup oldcg = new ComputationGroup(); oldcg.cnvcGroupCode = cg.cnvcGroupCode; oldcg = EntityMapping.Get(oldcg, trans) as ComputationGroup; EntityMapping.Delete(oldcg, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "计量单位组编码:" + cg.cnvcGroupCode; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); return(-1); } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); return(-1); } finally { ConnectionPool.ReturnConnection(conn); } return(1); } }
public int DeleteInventory(OperLog operLog, Entity.Inventory inv) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); Entity.Inventory oldinv = new Entity.Inventory(); oldinv.cnvcInvCode = inv.cnvcInvCode; oldinv = EntityMapping.Get(oldinv, trans) as Entity.Inventory; EntityMapping.Delete(oldinv, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "存货编码:" + inv.cnvcInvCode; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); return(-1); } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); return(-1); } finally { ConnectionPool.ReturnConnection(conn); } return(1); } }
public int DeleteProductClass(OperLog operLog, ProductClass pc) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); ProductClass oldpc = new ProductClass(); oldpc.cnvcProductClassCode = pc.cnvcProductClassCode; oldpc = EntityMapping.Get(oldpc, trans) as ProductClass; EntityMapping.Delete(oldpc, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "产品分类:" + pc.cnvcProductClassCode; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); return(-1); } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); return(-1); } finally { ConnectionPool.ReturnConnection(conn); } return(1); } }
//订单删除产品 public void DeleteDetail(OrderBookDetail detail, OperLog operLog) //,BusiLog busiLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { EntityMapping.Delete(detail, trans); string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "订单流水:" + detail.cnnOrderSerialNo.ToString() + ",产品编码:" + detail.cnvcInvCode; EntityMapping.Create(operLog, trans); //EntityMapping.Create(busiLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
public void BOMMOD(Entity.BillOfMaterials bom, Entity.BusiLog bl, bool isHis) { ConnectionPool.IsCenter = false; using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); Entity.OilStorage os = new OilStorage(bl.ToTable()); os.cnvcGoodsName = bom.cnvcGoodsName; os.cnvcGoodsType = bom.cnvcGoodsType; os = EntityMapping.Get(os, trans) as OilStorage; if (null == os) { throw new BusinessException(bexType.noobject, "库存获取错误"); } Guid gd = Guid.NewGuid(); //判断修改操作类型 改多为入库 改少为出库 //专供油出库 Entity.BillOfMaterials oldbom = new BillOfMaterials(bom.GetOriginalValue()); string strOperType = ""; if (oldbom.cnnCount > bom.cnnCount) { strOperType = InType.BOMModIn; } else { strOperType = InType.BOMModOut; } //验收单 //bom.cnvcInType = strOperType; bom.cndOperDate = dtSysTime; if (isHis) { Entity.BillOfMaterialsHis bomhis = new BillOfMaterialsHis(bom.GetOriginalValue()); EntityMapping.Delete(bomhis, trans); //bomhis.SynchronizeModifyValue(bom); EntityMapping.Create(bom, trans); } else { EntityMapping.Update(bom, trans); } if (bom.cnnCount != oldbom.cnnCount) { //库存日志 Entity.OilStorageLog ol = new OilStorageLog(bom.ToTable()); ol.cnvcDeptName = bl.cnvcDeptName; ol.cnvcOperType = strOperType; ol.cnnSerial = gd; ol.cnnLastCount = os.cnnStorageCount; ol.cnnInOutCount = oldbom.cnnCount - bom.cnnCount; //bom.cnnCount-oldbom.cnnCount; ol.cnnCurCount = os.cnnStorageCount + oldbom.cnnCount - bom.cnnCount; EntityMapping.Create(ol, trans); //库存 os.cnnStorageCount = ol.cnnCurCount; EntityMapping.Update(os, trans); } //日志 bl.cnnSerial = gd; bl.cnvcComments = "领料单修改,出入库量:" + (oldbom.cnnCount - bom.cnnCount); bl.cnvcOperType = OperType.OP203; bl.cndOperDate = dtSysTime; bl.cnvcSource = InSource.cs; EntityMapping.Create(bl, trans); trans.Commit(); } catch (BusinessException bex) { trans.Rollback(); LogAdapter.WriteBusinessException(bex); throw bex; } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
public void UpdateFormula(Entity.Formula formula, DataTable dtDosage, DataTable dtPacking, DataTable dtOperStandard, OperLog operLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { Entity.Formula fold = EntityMapping.Get(formula, trans) as Entity.Formula; if (fold == null) { throw new Exception("未找到配方"); } fold.SynchronizeModifyValue(formula); fold.IsUse = formula.IsUse; EntityMapping.Update(fold, trans); DataTable dtGoods = SqlHelper.ExecuteDataTable(trans, CommandType.Text, "select * from tbGoods where vcGoodsID='" + formula.cnvcProductCode + "'"); if (dtGoods.Rows.Count == 1 && formula.cnvcProductType == "FINALPRODUCT") { Goods goods = new Goods(dtGoods.Rows[0]); //goods.vcGoodsID = formula.cnvcProductCode; if (goods.vcGoodsName != formula.cnvcProductName) { goods.vcSpell = Helper.GetChineseSpell(formula.cnvcProductName); } goods.vcGoodsName = formula.cnvcProductName; goods.vcComments = formula.IsUse ? "1" : "0"; EntityMapping.Update(goods, trans); } DataTable dtHavedDosage = SqlHelper.ExecuteDataTable(trans, CommandType.Text, "select * from tbDosage where cnvcProductCode='" + formula.cnvcProductCode + "'"); DataTable dtHavedOperStandard = SqlHelper.ExecuteDataTable(trans, CommandType.Text, "select * from tbOperStandard where cnvcProductCode='" + formula.cnvcProductCode + "'"); //有的更新,没的添加 foreach (DataRow drDosage in dtDosage.Rows) { Dosage newdosage = new Dosage(drDosage); DataRow[] dr = dtHavedDosage.Select("cnvcCode='" + newdosage.cnvcCode + "'"); if (dr.Length > 0) { Dosage dosage = new Dosage(dr[0]); dosage.cnnCount = newdosage.cnnCount; dosage.cnnSum = newdosage.cnnSum; EntityMapping.Update(dosage, trans); } else { EntityMapping.Create(newdosage, trans); } } foreach (DataRow drPacking in dtPacking.Rows) { Dosage newdosage = new Dosage(drPacking); DataRow[] dr = dtHavedDosage.Select("cnvcCode='" + newdosage.cnvcCode + "'"); if (dr.Length > 0) { Dosage dosage = new Dosage(dr[0]); dosage.cnnCount = newdosage.cnnCount; dosage.cnnSum = newdosage.cnnSum; EntityMapping.Update(dosage, trans); } else { EntityMapping.Create(newdosage, trans); } } foreach (DataRow drDosage in dtHavedDosage.Rows) { Dosage dosage = new Dosage(drDosage); if (dosage.cnvcProductType == "Pack") { DataRow[] dr = dtPacking.Select("cnvcCode='" + dosage.cnvcCode + "'"); if (dr.Length == 0) { EntityMapping.Delete(dosage, trans); } } else { DataRow[] dr = dtDosage.Select("cnvcCode='" + dosage.cnvcCode + "'"); if (dr.Length == 0) { EntityMapping.Delete(dosage, trans); } } } foreach (DataRow drOperStandard in dtOperStandard.Rows) { OperStandard newoperStandard = new OperStandard(drOperStandard); DataRow[] dr = dtHavedOperStandard.Select("cnnSort=" + newoperStandard.cnnSort.ToString()); if (dr.Length > 0) { OperStandard operStandard = new OperStandard(dr[0]); operStandard.cnvcKey = newoperStandard.cnvcKey; operStandard.cnvcStandard = newoperStandard.cnvcStandard; EntityMapping.Update(operStandard, trans); } else { EntityMapping.Create(newoperStandard, trans); } } foreach (DataRow drOperStandard in dtHavedOperStandard.Rows) { OperStandard operStandard = new OperStandard(drOperStandard); DataRow[] dr = dtOperStandard.Select("cnnSort=" + operStandard.cnnSort.ToString()); if (dr.Length == 0) { EntityMapping.Delete(operStandard, trans); } } string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "配方编码:" + formula.cnvcProductCode; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
public static int DeleteOper(SqlConnection conn, Oper oper) { return(EntityMapping.Delete(oper, conn)); }
//删除某个某个操作员的功能 public static int DeleteOperFunc(SqlTransaction trans, OperFunc operFunc) { return(EntityMapping.Delete(operFunc, trans)); }
public static int DeleteSpecialOilDept(SqlTransaction trans, SpecialOilDept specialOilDept) { return(EntityMapping.Delete(specialOilDept, trans)); }