public Dept GetDeptById(int deptid) { Dept dept = new Dept(); dept.cnnDeptID = deptid; return(EntityMapping.Get(dept) as Dept); }
public void UpdateOrder(OrderBook order, 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); OrderBook oldOrder = new OrderBook(); oldOrder.cnnOrderSerialNo = order.cnnOrderSerialNo; oldOrder = EntityMapping.Get(oldOrder, trans) as OrderBook; if (oldOrder == null) { throw new Exception("订单未找到"); } oldOrder.cnvcOrderOperID = order.cnvcOrderOperID; oldOrder.cnvcOrderType = order.cnvcOrderType; oldOrder.cnvcProduceDeptID = order.cnvcProduceDeptID; oldOrder.cnvcOrderDeptID = order.cnvcOrderDeptID; if (oldOrder.cnvcOrderType == "WDO") { oldOrder.cndArrivedDate = order.cndArrivedDate; oldOrder.cnvcLinkPhone = order.cnvcLinkPhone; oldOrder.cnvcShipAddress = order.cnvcShipAddress; oldOrder.cnvcCustomName = order.cnvcCustomName; } //order.cnnOrderSerialNo = decimal.Parse(txtOrderSerialNo.Text); oldOrder.cndShipDate = order.cndShipDate; EntityMapping.Update(oldOrder, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "订单流水:" + oldOrder.cnnOrderSerialNo; 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 UpdateAssignLog(AssignDetail detail, OperLog operLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { // // AssignDetail detail = new AssignDetail(); // detail.cnnAssignSerialNo = detailLog.cnnAssignSerialNo; // detail.cnnOrderSerialNo = detailLog.cnnOrderSerialNo; // detail.cnvcProductCode = detailLog.cnvcProductCode; AssignDetail detailOld = EntityMapping.Get(detail, trans) as AssignDetail; if (detail.cnnCount != detailOld.cnnCount) { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); OrderSerialNo serialNo = new OrderSerialNo(); serialNo.cnvcFill = "0"; serialNo.cnnSerialNo = Convert.ToDecimal(EntityMapping.Create(serialNo, trans)); detailOld.cnnCount = detail.cnnCount; detailOld.cnnSum = Math.Round(detail.cnnCount * detailOld.cnnPrice, 2); EntityMapping.Update(detailOld, trans); AssignDetailLog detailLog = new AssignDetailLog(detailOld.ToTable()); detailLog.cnvcOperID = operLog.cnvcOperID; detailLog.cndOperDate = dtSysTime; detailLog.cnnSerialNo = serialNo.cnnSerialNo; EntityMapping.Create(detailLog, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产流水:" + detail.cnnAssignSerialNo.ToString() + ",日志流水:" + serialNo.cnnSerialNo.ToString(); 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 void UpdateBook(Book book, OperLog operLog) { 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.Book oldbook = new Book(); oldbook.cnnSerialNo = book.cnnSerialNo; oldbook = EntityMapping.Get(oldbook, trans) as Book; if (oldbook == null) { throw new Exception("未找到留言内容!"); } if (oldbook.cnvcState != "0") { throw new Exception("已确认的留言不能修改!"); } oldbook.cnvcBook = book.cnvcBook; oldbook.cmvcPublishID = book.cmvcPublishID; oldbook.cnvcPublishName = book.cnvcPublishName; oldbook.cndPublishDate = dtSysTime; oldbook.cnvcCheckDept = book.cnvcCheckDept; oldbook.cnvcCheckID = string.Empty; oldbook.cnvcCheckName = string.Empty; oldbook.cndcheckDate = DateTime.MinValue; EntityMapping.Update(oldbook, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "留言本流水号:" + oldbook.cnnSerialNo.ToString(); 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); } } }
/// <summary> /// 操作员登录 /// </summary> /// <param name="OperName"></param> /// <param name="PWD"></param> public void OperLogin(string OperName) { alOperFunc = new ArrayList(); oper = new Oper(); //安全比对 DataTable dtOper = SqlHelper.ExecuteDataTable(CommandType.Text, "select * from tbOper where cnvcOperName = '" + OperName + "'"); if (null == dtOper) { throw new BusinessException("操作员登录", "操作员名称或密码错误!"); } if (dtOper.Rows.Count == 0) { throw new BusinessException("操作员登录", "操作员名称或密码错误!"); } oper = new Oper(dtOper); //操作员功能列表 if (oper.cnnDeptID != 0)//=0为系统管理员 { //系统管理员具有所有权限 //否则比对权限列表 DataTable dtOperFunc = SqlHelper.ExecuteDataTable(CommandType.Text, "select * from tbOperFunc where cnnOperID = " + oper.cnnOperID); foreach (DataRow dr in dtOperFunc.Rows) { FuncList funcList = new FuncList(dr); alOperFunc.Add(funcList.cnvcFuncCode); } DataTable dtDeptFunc = SqlHelper.ExecuteDataTable(CommandType.Text, "select * from tbDeptFunc where cnnDeptID = " + oper.cnnDeptID); foreach (DataRow dr in dtDeptFunc.Rows) { FuncList funcList = new FuncList(dr); if (!alOperFunc.Contains(funcList.cnvcFuncCode)) { alOperFunc.Add(funcList.cnvcFuncCode); } } if (alOperFunc.Count == 0) { throw new BusinessException("操作员登录", "操作员无任何权限!"); } } if (oper.cnnDeptID == 0) { iDiscount = 0; } else { Dept dept = new Dept(); dept.cnnDeptID = oper.cnnDeptID; Dept oldDept = EntityMapping.Get(dept) as Dept; iDiscount = oldDept.cnnDiscount; } //折扣上限 }
public void BatchUpdateProduceCheck(ArrayList alCheck, string strProduceSerialNo, OperLog operLog) { 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); for (int i = 0; i < alCheck.Count; i++) { ProduceCheckLog check = alCheck[i] as ProduceCheckLog; ProduceCheckLog oldCheck = new ProduceCheckLog(); oldCheck.cnnProduceSerialNo = check.cnnProduceSerialNo; oldCheck.cnvcCode = check.cnvcCode; oldCheck = EntityMapping.Get(oldCheck, trans) as ProduceCheckLog; if (oldCheck == null) { throw new Exception("未找到指定产品生产库存"); } oldCheck.cnnCheckCount = check.cnnCheckCount; oldCheck.cnvcOperID = check.cnvcOperID; oldCheck.cndOperDate = dtSysTime; EntityMapping.Update(oldCheck, trans); } operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产流水:" + strProduceSerialNo; 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 UpdateWareHouse(OperLog operLog, Entity.Warehouse wh) { 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.Warehouse oldwh = new AMSApp.zhenghua.Entity.Warehouse(); oldwh.cnvcWhCode = wh.cnvcWhCode; oldwh = EntityMapping.Get(oldwh, trans) as AMSApp.zhenghua.Entity.Warehouse; oldwh.cnvcWhName = wh.cnvcWhName; oldwh.cnvcDepCode = wh.cnvcDepCode; oldwh.cnvcWhAddress = wh.cnvcWhAddress; oldwh.cnvcWhPhone = wh.cnvcWhPhone; oldwh.cnvcWhPerson = wh.cnvcWhPerson; oldwh.cnvcWhValueStyle = wh.cnvcWhValueStyle; oldwh.cnbFreeze = wh.cnbFreeze; oldwh.cnnFrequency = wh.cnnFrequency; oldwh.cnvcFrequency = wh.cnvcFrequency; oldwh.cnvcWhProperty = wh.cnvcWhProperty; oldwh.cnbShop = wh.cnbShop; EntityMapping.Update(oldwh, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "仓库编码:" + oldwh.cnvcWhCode; 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 AdjustProductLostSerial_Add(LostSerial ls, 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); LostSerial oldls = EntityMapping.Get(ls, trans) as LostSerial; if (oldls == null) { throw new Exception("未找到对应报损流水的产品!"); } oldls.cnnAddCount = ls.cnnAddCount; oldls.cnnReduceCount = ls.cnnReduceCount; oldls.cnvcOperID = operLog.cnvcOperID; oldls.cndOperDate = dtSysTime; EntityMapping.Update(oldls, trans); // ProductLostSerialLog productLostSerialLog = new ProductLostSerialLog(oldProductLostSerial.ToTable()); // productLostSerialLog.cnnProductLostSerialNo = oldProductLostSerial.cnnSerialNo; // EntityMapping.Create(productLostSerialLog, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产产品报损调整,报损流水:" + oldls.cnnLostSerialNo.ToString() + ",产品编码:" + ls.cnvcInvCode; 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 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 Oper GetUser(int userid, bool userIsOnline) { Oper oper = new Oper(); oper.cnnOperID = userid; oper = EntityMapping.Get(oper) as Oper; if (userIsOnline) { oper.LastActivityDate = DateTime.Now; EntityMapping.Update(oper); } return(oper); }
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 UpdatePwd(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); Oper oldOper = new Oper(); oldOper.cnvcOperID = oper.cnvcOperID; oldOper = EntityMapping.Get(oldOper, trans) as Oper; if (null == oldOper) { throw new Exception("无此用户"); } oldOper.cnvcOperPwd = oper.cnvcOperPwd; //DataSecurity.Encrypt(oper.cnvcOperPwd); EntityMapping.Update(oldOper, trans); BusiLog busiLog = new BusiLog(); busiLog.cndOperDate = dtSysTime; busiLog.cnnBusiSerialNo = Helper.GetSerialNo(trans); busiLog.cnvcComments = "修改密码"; 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 EntityObjectBase CommonQuery(EntityObjectBase eob) { SqlConnection conn = ConnectionPool.BorrowConnection(); try { return(EntityMapping.Get(eob, conn)); } finally { ConnectionPool.ReturnConnection(conn); } return(null); }
//订单更新产品 public void UpdateDetail(OrderBookDetail detail, 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); OrderBookDetail oldDetail = new OrderBookDetail(); oldDetail.cnnOrderSerialNo = detail.cnnOrderSerialNo; oldDetail.cnvcProductCode = detail.cnvcProductCode; oldDetail = EntityMapping.Get(oldDetail, trans) as OrderBookDetail; oldDetail.cnnOrderCount = detail.cnnOrderCount; oldDetail.cnnSum = detail.cnnOrderCount * oldDetail.cnnPrice; oldDetail.cnvcOperID = detail.cnvcOperID; oldDetail.cndOperDate = dtSysTime; EntityMapping.Update(oldDetail, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "订单流水:" + detail.cnnOrderSerialNo.ToString(); 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 void AddOperFunc(ArrayList alOperFuncList, int iOperID) { try { conn = ConnectionPool.BorrowConnection(); trans = conn.BeginTransaction(); for (int i = 0; i < alOperFuncList.Count; i++) { string strFuncCode = alOperFuncList[i].ToString(); OperFunc func = new OperFunc(); func.cnnOperID = iOperID; func.cnvcFuncCode = strFuncCode; OperFunc oldFunc = EntityMapping.Get(func, trans) as OperFunc; if (null == oldFunc) { EntityMapping.Create(func, 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); } }
public void InsertNT77(string strHardwareID, string strCardNo, string OperName) { NT77 nt77 = new NT77(); nt77.HardwareID = strHardwareID; nt77 = EntityMapping.Get(nt77) as NT77; if (nt77 == null) { nt77 = new NT77(); nt77.HardwareID = strHardwareID; nt77.CardNo = strCardNo; nt77.CreateDate = DateTime.Now; nt77.OperName = OperName; nt77.bIsUse = true; EntityMapping.Create(nt77); } }
public void UpdatePriority(Dept dept, OperLog operLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { Dept oldDept = new Dept(); oldDept.cnvcDeptID = dept.cnvcDeptID; oldDept = EntityMapping.Get(oldDept, trans) as Dept; if (oldDept == null) { throw new Exception("未找到相应的部门"); } oldDept.cnnPriority = dept.cnnPriority; EntityMapping.Update(oldDept, trans); string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "部门ID:" + dept.cnvcDeptID; 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 UpdateProductClass(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; oldpc.cnvcComments = pc.cnvcComments; oldpc.cnvcProductClassName = pc.cnvcProductClassName; oldpc.cnvcProductType = pc.cnvcProductType; EntityMapping.Update(pc, 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 int UpdateComputationGroup(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; oldcg.cnvcGroupName = cg.cnvcGroupName; EntityMapping.Update(cg, 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 UpdateProducer(OperLog operLog, Entity.Producer producer) { 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.Producer oldproducer = new AMSApp.zhenghua.Entity.Producer(); oldproducer.cnnProducerID = producer.cnnProducerID; oldproducer = EntityMapping.Get(oldproducer, trans) as AMSApp.zhenghua.Entity.Producer; oldproducer.cnvcProducerName = producer.cnvcProducerName; EntityMapping.Update(oldproducer, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产员编码:" + oldproducer.cnnProducerID.ToString(); 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 void CancelCard(Oper opers) { try { conn = ConnectionPool.BorrowConnection(); trans = conn.BeginTransaction(); Oper oldOper = EntityMapping.Get(opers, trans) as Oper; //DataTable dtOper = SqlHelper.ExecuteDataTable(trans,CommandType.Text,"select * from tbOper where cnvcCardNo is not null and cnvcCardNo = 'aaa"+opers.cnvcCardNo+"'"); if (null == oldOper) { throw new BusinessException("操作员管理", "未找到操作员!"); } oldOper.cnvcCardNo = ""; EntityMapping.Update(opers, 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); } }
public static Oper IsUser(string strOperID, string strOperPwd) { SqlConnection conn = ConnectionPool.BorrowConnection(); Oper oper = null; try { oper = new Oper(); oper.cnvcOperID = strOperID; oper = EntityMapping.Get(oper, conn) as Oper; if (null == oper) { throw new Exception("无此用户"); } if (oper.cndInvalidDate <= DateTime.MinValue) { throw new Exception("用户已失效"); } if (oper.cnvcOperPwd != DataSecurity.Encrypt(strOperPwd)) { throw new Exception("密码无效"); } //写登录日志 BusiLog loginLog = new BusiLog(); loginLog.cndOperDate = Helper.GetSysTime(conn); loginLog.cnnBusiSerialNo = Helper.GetSerialNo(conn); loginLog.cnvcFuncCode = "登录"; loginLog.cnvcOperID = oper.cnvcOperID; loginLog.cnvcComments = "登录"; EntityMapping.Create(loginLog, conn); } catch (Exception ex) { LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } return(oper); }
public int UpdateDept(Dept dept, BusiLog busiLog) { //SqlConnection conn = ConnectionPool.BorrowConnection(); int iRet = 0; using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { BusiLogAccess.AddBusiLog(trans, busiLog); Dept olddept = new Dept(); olddept.cnvcDeptID = dept.cnvcDeptID; olddept = EntityMapping.Get(olddept, trans) as Dept; olddept.cnbValidate = dept.cnbValidate; olddept.cnvcDeptName = dept.cnvcDeptName; olddept.cnvcParentDeptID = dept.cnvcParentDeptID; iRet = DeptAccess.UpdateDept(trans, olddept); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); throw sex; } catch (Exception ex) { trans.Rollback(); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } return(iRet); }
public void UpdateNT77(List <NT77> lnt) { try { conn = ConnectionPool.BorrowConnection(); trans = conn.BeginTransaction(); foreach (NT77 nt in lnt) { NT77 oldnt = EntityMapping.Get(nt, trans) as NT77; oldnt.bIsUse = nt.bIsUse; oldnt.OperName = nt.OperName; EntityMapping.Update(oldnt, 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); } }
public void AddOrder(OrderBook orderBook, DataTable dtOrderBookDetail, 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); if (orderBook.cnnOrderSerialNo > 0) { OrderBook oldOrder = new OrderBook(); oldOrder.cnnOrderSerialNo = orderBook.cnnOrderSerialNo; oldOrder = EntityMapping.Get(oldOrder, trans) as OrderBook; if (oldOrder == null) { throw new Exception("订单未找到"); } oldOrder.cnvcOperID = orderBook.cnvcOperID; oldOrder.cnvcOrderType = orderBook.cnvcOrderType; oldOrder.cnvcProduceDeptID = orderBook.cnvcProduceDeptID; oldOrder.cnvcOrderDeptID = orderBook.cnvcOrderDeptID; if (oldOrder.cnvcOrderType == "WDO" || oldOrder.cnvcOrderType == "WDOSELF") { oldOrder.cndArrivedDate = orderBook.cndArrivedDate; oldOrder.cnvcLinkPhone = orderBook.cnvcLinkPhone; oldOrder.cnvcShipAddress = orderBook.cnvcShipAddress; oldOrder.cnvcCustomName = orderBook.cnvcCustomName; } oldOrder.cndShipDate = orderBook.cndShipDate; oldOrder.cndOrderDate = orderBook.cndOrderDate; EntityMapping.Update(oldOrder, trans); SqlHelper.ExecuteNonQuery(trans, CommandType.Text, "delete from tborderbookdetail where cnnorderserialno=" + orderBook.cnnOrderSerialNo.ToString()); foreach (DataRow drOrderBookDetail in dtOrderBookDetail.Rows) { OrderBookDetail detail = new OrderBookDetail(drOrderBookDetail); detail.cnnOrderSerialNo = orderBook.cnnOrderSerialNo; EntityMapping.Create(detail, trans); } } else { OrderSerialNo serialNo = new OrderSerialNo(); serialNo.cnvcFill = "0"; serialNo.cnnSerialNo = Convert.ToDecimal(EntityMapping.Create(serialNo, trans)); orderBook.cnnOrderSerialNo = serialNo.cnnSerialNo; orderBook.cndOperDate = dtSysTime; orderBook.cnvcOperID = operLog.cnvcOperID; EntityMapping.Create(orderBook, trans); //SqlHelper.ExecuteNonQuery(trans,CommandType.Text,"delete from tborderbookdetail where cnnorderserialno="+orderBook.cnnOrderSerialNo.ToString()) ; foreach (DataRow drOrderBookDetail in dtOrderBookDetail.Rows) { OrderBookDetail detail = new OrderBookDetail(drOrderBookDetail); detail.cnnOrderSerialNo = serialNo.cnnSerialNo; EntityMapping.Create(detail, trans); } } operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "订单流水:" + orderBook.cnnOrderSerialNo; 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 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 void DeleteAssignLog(ProduceLog produceLog, OperLog operLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); OrderSerialNo serialNo = new OrderSerialNo(); serialNo.cnvcFill = "0"; serialNo.cnnSerialNo = Convert.ToDecimal(EntityMapping.Create(serialNo, trans)); ProduceLog oldLog = new ProduceLog(); oldLog.cnnProduceSerialNo = produceLog.cnnProduceSerialNo; oldLog = EntityMapping.Get(oldLog, trans) as ProduceLog; if (oldLog == null) { throw new Exception("生产计划不存在"); } if (oldLog.cnvcProduceState != "6") { throw new Exception("生产计划不在已分货状态,不能清除分货数据"); } if (oldLog.cnvcProduceState == "7") { throw new Exception("已分货出库"); } oldLog.cnvcOperID = produceLog.cnvcOperID; oldLog.cndOperDate = dtSysTime; //清除分货数据 string strsql = "delete from tbassignlog where cnnproduceserialno=" + produceLog.cnnProduceSerialNo.ToString(); // DataTable dtal = SqlHelper.ExecuteDataTable(trans,CommandType.Text,strsql); // if(dtal.Rows.Count == 0) throw new Exception("未找到分货数据"); // Entity.AssignLog al = new AssignLog(dtal); // EntityMapping.Delete(al,trans); SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strsql); strsql = "delete from tbassigndetail where cnnproduceserialno=" + produceLog.cnnProduceSerialNo.ToString(); SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strsql); strsql = "update tbproducechecklog set cnnassigncount=0 where cnnproduceserialno=" + produceLog.cnnProduceSerialNo.ToString(); SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strsql); //更新订单生产计划状态 string strUpdateOrder = "update tbOrderBook set cnvcOrderState='1' " + " where cnnOrderSerialNo in (select cnnOrderSerialNo from tbProduceOrderLog where cnvcType='0' and cnnProduceSerialNo=" + oldLog.cnnProduceSerialNo + ") "; SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strUpdateOrder); //更新生产计划状态 oldLog.cnvcProduceState = "5"; EntityMapping.Update(oldLog, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产流水:" + produceLog.cnnProduceSerialNo.ToString(); 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 void UpdateAssignLog(AssignDetail detail, OperLog operLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); Entity.ProduceCheckLog pcl = new ProduceCheckLog(); pcl.cnnProduceSerialNo = detail.cnnProduceSerialNo; pcl.cnvcInvCode = detail.cnvcInvCode; pcl = EntityMapping.Get(pcl, trans) as ProduceCheckLog; if (pcl == null) { throw new Exception("无法定位生产"); } AssignDetail detailOld = EntityMapping.Get(detail, trans) as AssignDetail; pcl.cnnAssignCount = pcl.cnnAssignCount + detail.cnnAssignCount - detailOld.cnnAssignCount; EntityMapping.Update(pcl, trans); // if(detail.cnnAssignCount != detailOld.cnnAssignCount) // { // OrderSerialNo serialNo = new OrderSerialNo(); // serialNo.cnvcFill = "0"; // serialNo.cnnSerialNo = Convert.ToDecimal(EntityMapping.Create(serialNo, trans)); string strComments = ""; detailOld.cnnAssignCount = detail.cnnAssignCount; EntityMapping.Update(detailOld, trans); strComments = "[" + detail.cnvcInvCode + ":" + detail.cnnAssignCount + "]"; //} operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "分货流水:" + detail.cnnAssignSerialNo.ToString() + strComments; 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); } } }