コード例 #1
0
ファイル: AscmRfidService.cs プロジェクト: gofixiao/Midea
 public void Delete(AscmRfid ascmRfid)
 {
     try
     {
         YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmRfid>(ascmRfid);
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmRfid)", ex);
         throw ex;
     }
 }
コード例 #2
0
 public void Save(AscmRfid ascmRfid)
 {
     try
     {
         int count = YnDaoHelper.GetInstance().nHibernateHelper.GetCount("select count(*) from AscmRfid where id='" + ascmRfid.id + "'");
         if (count == 0)
         {
             int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(organizationId) from AscmRfid");
             using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
             {
                 try
                 {
                     maxId++;
                     ascmRfid.organizationId = maxId;
                     YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmRfid);
                     tx.Commit();//正确执行提交
                 }
                 catch (Exception ex)
                 {
                     tx.Rollback();//回滚
                     throw ex;
                 }
             }
         }
         else
         {
             YnBaseClass2.Helper.LogHelper.GetLog().Error("已存在(Save AscmRfid)"+ascmRfid.id.ToString());
         }
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("保存失败(Save AscmRfid)", ex);
         throw ex;
     }
 }
コード例 #3
0
 public void Update(AscmRfid ascmRfid)
 {
     int count = YnDaoHelper.GetInstance().nHibernateHelper.GetCount("select count(*) from AscmRfid where id='" + ascmRfid.id + "'");
     if (count > 0)
     {
         using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         {
             try
             {
                 YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmRfid>(ascmRfid);
                 tx.Commit();//正确执行提交
             }
             catch (Exception ex)
             {
                 tx.Rollback();//回滚
                 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmRfid)", ex);
                 throw ex;
             }
         }
     }
     else
     {
         throw new Exception("标签SN不存在,无法更新\"" + ascmRfid.id + "\"!");
     }
 }
コード例 #4
0
ファイル: PublicController.cs プロジェクト: gofixiao/Midea
        public ContentResult EmployeeCarSave(AscmEmployeeCar ascmEmployeeCar_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                AscmEmployeeCar ascmEmployeeCar = null;
                if (id.HasValue)
                {
                    ascmEmployeeCar = AscmEmployeeCarService.GetInstance().Get(id.Value);
                }
                else
                {
                    ascmEmployeeCar = new AscmEmployeeCar();
                }
                if (ascmEmployeeCar == null)
                    throw new Exception("保存员工车辆基本信息失败!");
                if (ascmEmployeeCar_Model.plateNumber == null || ascmEmployeeCar_Model.plateNumber.Trim() == "")
                    throw new Exception("员工车辆车牌号不能为空!");
                if (ascmEmployeeCar_Model.rfid.Length != 10)
                {
                    throw new Exception("rfid编号可能有错误【" + ascmEmployeeCar_Model.rfid.Trim() + "】,请检查,请输入后4位或后6位!");
                }
                //if (ascmEmployeeCar_Model.employeeId==0)
                //    throw new Exception("必须选择输入员工!");

                ascmEmployeeCar.plateNumber = ascmEmployeeCar_Model.plateNumber.Trim();
                ascmEmployeeCar.spec = ascmEmployeeCar_Model.spec;
                ascmEmployeeCar.color = ascmEmployeeCar_Model.color;
                ascmEmployeeCar.seatCount = ascmEmployeeCar_Model.seatCount;
                ascmEmployeeCar.rfid = ascmEmployeeCar_Model.rfid.Trim();
                ascmEmployeeCar.memo = ascmEmployeeCar_Model.memo;
                //ascmEmployeeCar.employeeId = ascmEmployeeCar_Model.employeeId;

                ascmEmployeeCar.employeeDocNumber = ascmEmployeeCar_Model.employeeDocNumber;
                if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeDocNumber))
                    ascmEmployeeCar.employeeDocNumber = ascmEmployeeCar.employeeDocNumber.Trim();

                ascmEmployeeCar.employeeName = ascmEmployeeCar_Model.employeeName;
                if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeName))
                    ascmEmployeeCar.employeeName = ascmEmployeeCar.employeeName.Trim();

                ascmEmployeeCar.employeeSex = ascmEmployeeCar_Model.employeeSex;
                if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeSex))
                    ascmEmployeeCar.employeeSex = ascmEmployeeCar.employeeSex.Trim();

                ascmEmployeeCar.employeeIdNumber = ascmEmployeeCar_Model.employeeIdNumber;
                if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeIdNumber))
                    ascmEmployeeCar.employeeIdNumber = ascmEmployeeCar.employeeIdNumber.Trim();
                ascmEmployeeCar.employeeOfficeTel = ascmEmployeeCar_Model.employeeOfficeTel;
                ascmEmployeeCar.employeeMobileTel = ascmEmployeeCar_Model.employeeMobileTel;
                ascmEmployeeCar.exemption = ascmEmployeeCar_Model.exemption;
                ascmEmployeeCar.employeeLevel = ascmEmployeeCar_Model.employeeLevel;

                AscmRfid ascmRfid_Old = null;
                AscmRfid ascmRfid_New_Update = null;
                AscmRfid ascmRfid_New_Save = null;
                bool _new = true;
                if (!id.HasValue)
                {
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where plateNumber='" + ascmEmployeeCar_Model.plateNumber.Trim() + "'");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int iCount = 0;
                    if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                        throw new Exception("已经存在此员工车辆车牌号【" + ascmEmployeeCar_Model.plateNumber.Trim() + "】!");
                    if (!string.IsNullOrEmpty(ascmEmployeeCar_Model.rfid))
                    {
                        object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where rfid='" + ascmEmployeeCar_Model.rfid.Trim() + "'");
                        if (object1 == null)
                            throw new Exception("查询异常!");
                        //int iCount = 0;
                        if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                            throw new Exception("已经分配此车辆RFID【" + ascmEmployeeCar_Model.rfid.Trim() + "】!");
                    }
                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmEmployeeCar");
                    ascmEmployeeCar.id = maxId+1;
                    //AscmEmployeeCarService.GetInstance().Save(ascmEmployeeCar);
                }
                else
                {
                    _new = false;
                    if (ascmEmployeeCar.rfid!=null)
                        ascmRfid_Old = AscmRfidService.GetInstance().Get(ascmEmployeeCar.rfid.Trim());

                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where plateNumber='" + ascmEmployeeCar_Model.plateNumber.Trim() + "' and id<>" + id.Value + "");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int iCount = 0;
                    if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                        throw new Exception("已经存在此员工车辆车牌号【" + ascmEmployeeCar_Model.plateNumber.Trim() + "】!");
                    if (!string.IsNullOrEmpty(ascmEmployeeCar_Model.rfid))
                    {
                        object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where rfid='" + ascmEmployeeCar_Model.rfid.Trim() + "' and id<>" + id.Value + "");
                        if (object1 == null)
                            throw new Exception("查询异常!");
                        //int iCount = 0;
                        if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                            throw new Exception("已经分配此车辆RFID【" + ascmEmployeeCar_Model.rfid.Trim() + "】!");
                    }
                    //AscmEmployeeCarService.GetInstance().Update(ascmEmployeeCar);
                }
                ascmRfid_New_Update = AscmRfidService.GetInstance().Get(ascmEmployeeCar.rfid.Trim());
                if (ascmRfid_Old != null && ascmRfid_New_Update != null)
                {
                    if (ascmRfid_Old.id == ascmRfid_New_Update.id)
                    {
                        ascmRfid_Old = null;
                    }
                }
                if (ascmRfid_Old != null)
                {
                    ascmRfid_Old.bindType = AscmRfid.BindTypeDefine.employeeCar;
                    ascmRfid_Old.bindId = "";
                    ascmRfid_Old.status = AscmRfid.StatusDefine.none;
                    //ascmRfid_Old.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                }
                if (ascmRfid_New_Update != null)
                {
                    ascmRfid_New_Update.bindType = AscmRfid.BindTypeDefine.employeeCar;
                    ascmRfid_New_Update.bindId = ascmEmployeeCar.id.ToString();
                    ascmRfid_New_Update.status = AscmRfid.StatusDefine.inUse;
                    //ascmRfid_New_Update.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                }
                else
                {
                    ascmRfid_New_Save = new AscmRfid();
                    ascmRfid_New_Save.id = ascmEmployeeCar.rfid;
                    ascmRfid_New_Save.createUser = "";
                    //ascmRfid_New_Save.createTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                    //ascmRfid_New_Save.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                    ascmRfid_New_Save.bindType = AscmRfid.BindTypeDefine.employeeCar;
                    ascmRfid_New_Save.bindId = ascmEmployeeCar.id.ToString();
                    ascmRfid_New_Save.status = AscmRfid.StatusDefine.inUse;
                }
                /*
                if (string.IsNullOrEmpty(ascmEmployeeCar_Model.rfid))
                {
                    ascmEmployeeCar.rfid = "";
                    //取消绑定
                    if (ascmRfid_Old != null)
                    {
                        ascmRfid_Old.bindId = "";
                        ascmRfid_Old.status = "";
                    }
                }
                else
                {
                    //增加绑定
                    ascmRfid_New = AscmRfidService.GetInstance().Get(ascmEmployeeCar_Model.rfid.Trim());
                    if (ascmRfid_New == null)
                        throw new Exception("RFID标签号码不存在!");
                    if (ascmRfid_New.bindType != AscmRfid.BindTypeDefine.employeeCar)
                        throw new Exception("请选择[" + AscmRfid.BindTypeDefine.DisplayText(ascmRfid_New.bindType) + "]类型的RFID标签!");
                    if (ascmRfid_Old != null)
                    {
                        //存在原绑定
                        if (ascmRfid_Old.id == ascmRfid_New.id)
                        {
                            //没有改变绑定
                            ascmRfid_Old = null;
                        }
                        else
                        {
                            //新绑定
                            ascmRfid_Old.bindId = "";
                            ascmRfid_Old.status = "";

                            if (!string.IsNullOrEmpty(ascmRfid_New.status) && ascmRfid_New.status != AscmRfid.StatusDefine.cancel)
                                throw new Exception("RFID标签【" + ascmRfid_New.id + "】已经处于[" + AscmRfid.StatusDefine.DisplayText(ascmRfid_New.status) + "]状态,不能重复绑定!");
                            if (!string.IsNullOrEmpty(ascmRfid_New.bindId))
                                throw new Exception("RFID标签【" + ascmRfid_New.id + "】已经绑定[" + ascmRfid_New.bindId + "],不能重复绑定!");

                            ascmRfid_New.bindId = ascmEmployeeCar.id.ToString();
                            ascmRfid_New.status = "";
                            ascmEmployeeCar.rfid = ascmRfid_New.id;
                        }
                    }
                    else
                    {
                        ascmRfid_New.bindId = ascmEmployeeCar.id.ToString();
                        ascmRfid_New.status = "";
                        ascmEmployeeCar.rfid = ascmRfid_New.id;
                    }
                }
                */
                AscmEmployeeCarService.GetInstance().Save(_new, ascmEmployeeCar, ascmRfid_Old, ascmRfid_New_Update, ascmRfid_New_Save);
                /*
                using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
                {
                    try
                    {
                        if (!id.HasValue)
                        {
                            YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmEmployeeCar);
                        }
                        else
                        {
                            YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmEmployeeCar);
                        }
                        if (ascmRfid_Old!=null)
                            YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_Old);
                        if (ascmRfid_New != null)
                            YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_New);
                        tx.Commit();//正确执行提交
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();//回滚
                        throw ex;
                    }
                }*/
                jsonObjectResult.result = true;
                jsonObjectResult.message = "";
                jsonObjectResult.id = ascmEmployeeCar.id.ToString();
                jsonObjectResult.entity = ascmEmployeeCar;
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
コード例 #5
0
ファイル: PublicController.cs プロジェクト: gofixiao/Midea
        public ContentResult RfidSave(string rfidStart, string rfidEnd, string bindTypeDefine)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                if (string.IsNullOrEmpty(rfidStart) || string.IsNullOrEmpty(rfidEnd))
                    throw new Exception("RFID号码段录入错误!");
                long _rfidStart = 0;
                long _rfidEnd = 0;
                long.TryParse(rfidStart, out _rfidStart);
                long.TryParse(rfidEnd, out _rfidEnd);
                if (_rfidStart == 0 || _rfidEnd == 0 || _rfidStart > _rfidEnd)
                    throw new Exception("RFID号码段录入错误!");
                //if (_rfidEnd - _rfidStart + 1 != giftCardPublishMain_Model.number)
                //    throw new Exception("礼卡号码段与录入数量不匹配!");
                if(_rfidEnd - _rfidStart+1>500)
                    throw new Exception("一次添加不能超过500!");
                if (string.IsNullOrEmpty(bindTypeDefine))
                    throw new Exception("必须选择RFID类型!");

                List<AscmRfid> listAscmRfid_New = new List<AscmRfid>();
                List<AscmRfid> listAscmRfid = AscmRfidService.GetInstance().GetList(" from AscmRfid where id>='" + rfidStart + "' and id<='" + rfidEnd + "'");
                for (long code = _rfidStart; code <= _rfidEnd; code++)
                {
                    string sCode = string.Format("{0:" + YnBaseClass2.Helper.StringHelper.Repeat('0', rfidStart.Trim().Length) + "}", code);
                    AscmRfid ascmRfid = listAscmRfid.Find(P => P.id == sCode);
                    if (ascmRfid != null)
                        throw new Exception("RFID已经存在[" + sCode + "]!");
                    ascmRfid = new AscmRfid();
                    ascmRfid.id = sCode;
                    ascmRfid.bindType = bindTypeDefine;
                    ascmRfid.bindId = "";
                    ascmRfid.status = "";
                    listAscmRfid_New.Add(ascmRfid);
                }

                AscmRfidService.GetInstance().Save(listAscmRfid_New);

                jsonObjectResult.result = true;
                jsonObjectResult.message = "";
                //jsonObjectResult.id = ascmEmployeeCar.id.ToString();
                //jsonObjectResult.entity = ascmEmployeeCar;
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
コード例 #6
0
        public void Save(bool _new, AscmEmployeeCar ascmEmployeeCar, AscmRfid ascmRfid_Old, AscmRfid ascmRfid_New_Update, AscmRfid ascmRfid_New_Save)
        {
            try
            {
                DateTime dtServerTime = MideaAscm.Dal.YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentDate("AscmEmployeeCar");
                ascmEmployeeCar.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                if (ascmRfid_Old != null)
                    ascmRfid_Old.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                if (ascmRfid_New_Update != null)
                    ascmRfid_New_Update.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                if (ascmRfid_New_Save != null)
                    ascmRfid_New_Save.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
                {
                    try
                    {
                        if (_new)
                        {
                            ascmEmployeeCar.createTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                            YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmEmployeeCar);
                        }
                        else
                        {
                            YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmEmployeeCar);
                        }
                        if (ascmRfid_Old != null)
                            YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_Old);
                        if (ascmRfid_New_Update != null)
                            YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_New_Update);
                        if (ascmRfid_New_Save != null)
                        {
                            ascmRfid_New_Save.createTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                            YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmRfid_New_Save);
                        }
                        tx.Commit();//正确执行提交
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();//回滚
                        throw ex;
                    }
                }

            }
            catch (Exception ex)
            {
                YnBaseClass2.Helper.LogHelper.GetLog().Error("保存失败(Save AscmEmployeeCar)", ex);
                throw ex;
            }
        }
コード例 #7
0
        public ContentResult DriverSave(AscmDriver ascmDriver_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                string userName = string.Empty;
                if (User.Identity.IsAuthenticated)
                {
                    userName = User.Identity.Name;
                }

                if (ascmDriver_Model.rfid == null || ascmDriver_Model.rfid == "")
                    throw new Exception("必须输入RFID编号");
                string rfid = ascmDriver_Model.rfid.Trim();
                AscmSupplier ascmSupplier = null;
                AscmDriver ascmDriver = null;
                AscmRfid ascmRfid = null;
                AscmRfid ascmRfidOld = null;
                if (id.HasValue)
                {
                    ascmDriver = AscmDriverService.GetInstance().Get(id.Value);
                    if (ascmDriver == null)
                        throw new Exception("保存司机失败!");
                    ascmDriver.modifyUser = userName;
                    ascmDriver.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    ascmSupplier = AscmSupplierService.GetInstance().Get(ascmDriver.supplierId);
                    if (ascmDriver.rfid != rfid)
                    {
                        object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmRfid where id='" + rfid + "'");
                        if (object1 == null)
                            throw new Exception("查询异常!");
                        int count = 0;
                        if (int.TryParse(object1.ToString(), out count) && count > 0)
                            throw new Exception("已存在编号【" + rfid + "】");

                        ascmRfidOld = AscmRfidService.GetInstance().Get(ascmDriver.sn);
                        if (ascmRfidOld != null)
                        {
                            object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmDriverDelivery where driverSn='" + ascmRfidOld.id + "'");
                            if (object1 == null)
                                throw new Exception("查询异常!");
                            count = 0;
                            if (int.TryParse(object1.ToString(), out count) && count > 0)
                                throw new Exception("不能修改已绑定物料的司机编号");
                        }

                        ascmRfid = new AscmRfid();
                        ascmRfid.id = rfid;
                        ascmRfid.createUser = userName;
                        ascmRfid.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        ascmRfid.modifyUser = userName;
                        ascmRfid.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        ascmRfid.bindType = AscmRfid.BindTypeDefine.driver;
                        ascmRfid.bindId = rfid;
                        ascmRfid.status = AscmRfid.StatusDefine.inUse;
                    }
                }
                else
                {
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmRfid where id='" + rfid + "'");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int count = 0;
                    if (int.TryParse(object1.ToString(), out count) && count > 0)
                        throw new Exception("已存在编号");
                    ascmSupplier = AscmSupplierService.GetInstance().Get(ascmDriver_Model.supplierId);
                    if (ascmSupplier == null)
                        throw new Exception("供应商不存在");

                    ascmDriver = new AscmDriver();
                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmDriver");
                    ascmDriver.id = ++maxId;
                    ascmDriver.supplierId = ascmDriver_Model.supplierId;
                    ascmDriver.status = ascmDriver_Model.status;
                    ascmDriver.createUser = userName;
                    ascmDriver.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    ascmDriver.modifyUser = userName;
                    ascmDriver.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");

                    ascmRfid = new AscmRfid();
                    ascmRfid.id = rfid;
                    ascmRfid.createUser = userName;
                    ascmRfid.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    ascmRfid.modifyUser = userName;
                    ascmRfid.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    ascmRfid.bindType = AscmRfid.BindTypeDefine.driver;
                    ascmRfid.bindId = rfid;
                    ascmRfid.status = AscmRfid.StatusDefine.inUse;
                }

                if (!string.IsNullOrEmpty(ascmDriver_Model.name))
                {
                    ascmDriver.name = ascmDriver_Model.name.Trim();

                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject(
                        "select count(*) from AscmDriver where supplierId=" + ascmDriver.supplierId + " and name='" + ascmDriver.name + "' and id<>" + ascmDriver.id);
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int count = 0;
                    if (int.TryParse(object1.ToString(), out count) && count > 0)
                        throw new Exception("供应商【" + ascmSupplier.name + "】中已存在司机【" + ascmDriver.name + "】");
                }

                ascmDriver.sn = rfid;
                ascmDriver.rfid = rfid;
                ascmDriver.sex = ascmDriver_Model.sex;
                if (!string.IsNullOrEmpty(ascmDriver_Model.idNumber))
                    ascmDriver.idNumber = ascmDriver_Model.idNumber.Trim();
                if (!string.IsNullOrEmpty(ascmDriver_Model.mobileTel))
                    ascmDriver.mobileTel = ascmDriver_Model.mobileTel.Trim();
                if (!string.IsNullOrEmpty(ascmDriver_Model.plateNumber))
                    ascmDriver.plateNumber = ascmDriver_Model.plateNumber.Trim();
                ascmDriver.load = ascmDriver_Model.load;
                if (!string.IsNullOrEmpty(ascmDriver_Model.description))
                    ascmDriver.description = ascmDriver_Model.description.Trim();
                ascmDriver.type = ascmDriver_Model.type;

                using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
                {
                    try
                    {
                        if (ascmDriver != null)
                            YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdate(ascmDriver);

                        if (ascmRfid != null)
                            YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdate(ascmRfid);

                        if (ascmRfidOld != null)
                            YnDaoHelper.GetInstance().nHibernateHelper.Delete(ascmRfidOld);

                        tx.Commit();//正确执行提交
                        jsonObjectResult.result = true;
                        jsonObjectResult.id = ascmDriver.id.ToString();
                        jsonObjectResult.entity = ascmDriver;
                        jsonObjectResult.message = "";
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();//回滚
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
コード例 #8
0
        public ContentResult ContainerSave(AscmContainer ascmContainer_Model, string id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                string userName = string.Empty;
                if (User.Identity.IsAuthenticated)
                {
                    userName = User.Identity.Name;
                }

                if (id != null && id.Trim() != "")
                {
                    AscmContainer ascmContainer = AscmContainerService.GetInstance().Get(id);
                    if (ascmContainer == null)
                        throw new Exception("保存容器失败!");
                    if (!string.IsNullOrEmpty(ascmContainer_Model.description))
                        ascmContainer.description = ascmContainer_Model.description.Trim();
                    ascmContainer.modifyUser = userName;
                    ascmContainer.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");

                    AscmContainerService.GetInstance().Update(ascmContainer);
                    jsonObjectResult.id = ascmContainer.sn;
                    jsonObjectResult.entity = ascmContainer;
                }
                else
                {
                    AscmContainerSpec ascmContainerSpec = AscmContainerSpecService.GetInstance().Get(ascmContainer_Model.specId);
                    if (ascmContainerSpec == null)
                        throw new Exception("容器规格不能为空!");

                    if (ascmContainer_Model.startSn == null || ascmContainer_Model.startSn.Trim() == "")
                        throw new Exception("开始编号不能为空");
                    if (ascmContainer_Model.endSn == null || ascmContainer_Model.endSn.Trim() == "")
                        throw new Exception("结束编号不能为空");
                    if (ascmContainer_Model.startSn.Trim().Length != ascmContainer_Model.endSn.Trim().Length)
                        throw new Exception("开始编号和结束编号长度不一致");
                    long startSn = 0, endSn = 0;
                    long.TryParse(ascmContainer_Model.startSn, out startSn);
                    long.TryParse(ascmContainer_Model.endSn, out endSn);
                    if (startSn == 0 || endSn == 0 || startSn > endSn)
                        throw new Exception("容器编号输入错误");
                    if (endSn - startSn + 1 > 500)
                        throw new Exception("单次添加不能超过500");
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmRfid where id between '" + ascmContainer_Model.startSn.Trim() + "' and '" + ascmContainer_Model.endSn.Trim() + "'");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int count = 0;
                    if (int.TryParse(object1.ToString(), out count) && count > 0)
                        throw new Exception("已存在编号");

                    List<AscmContainer> listAscmContainer = new List<AscmContainer>();
                    List<AscmRfid> listAscmRfid = new List<AscmRfid>();
                    for (; startSn <= endSn; startSn++)
                    {
                        AscmContainer ascmContainer = new AscmContainer();
                        string sn = string.Format("{0:000000}", startSn);//生成六位数的ID
                        ascmContainer.sn = sn;
                        ascmContainer.specId = ascmContainer_Model.specId;
                        ascmContainer.rfid = ascmContainer.sn + "000000000000000000";
                        ascmContainer.supplierId = ascmContainer_Model.supplierId;
                        if (!string.IsNullOrEmpty(ascmContainer_Model.description))
                            ascmContainer.description = ascmContainer_Model.description.Trim();
                        ascmContainer.status = ascmContainer_Model.status;
                        ascmContainer.createUser = userName;
                        ascmContainer.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        ascmContainer.modifyUser = userName;
                        ascmContainer.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        listAscmContainer.Add(ascmContainer);

                        AscmRfid ascmRfid = new AscmRfid();
                        ascmRfid.id = ascmContainer.sn;
                        ascmRfid.epcId = ascmContainer.rfid;
                        ascmRfid.createUser = userName;
                        ascmRfid.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        ascmRfid.modifyUser = userName;
                        ascmRfid.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        ascmRfid.bindType = AscmRfid.BindTypeDefine.container;
                        ascmRfid.bindId = ascmContainer.sn;
                        //ascmRfid.bindType = AscmRfid.BindTypeDefine.container;
                        ascmRfid.status = AscmRfid.StatusDefine.inUse;
                        listAscmRfid.Add(ascmRfid);
                    }

                    using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
                    {
                        try
                        {
                            if (listAscmContainer.Count > 0)
                                YnDaoHelper.GetInstance().nHibernateHelper.SaveList(listAscmContainer);

                            if (listAscmRfid.Count > 0)
                                YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdateList(listAscmRfid);

                            tx.Commit();//正确执行提交
                        }
                        catch (Exception ex)
                        {
                            tx.Rollback();//回滚
                            throw ex;
                        }
                    }
                }
                jsonObjectResult.result = true;
                jsonObjectResult.message = "";
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
コード例 #9
0
ファイル: AscmRfidService.cs プロジェクト: gofixiao/Midea
 public void Update(AscmRfid ascmRfid)
 {
     //int count = YnDaoHelper.GetInstance().nHibernateHelper.GetCount("select count(*) from AscmRfid where id<>" + ascmRfid.id + " and docNumber='" + ascmRfid.docNumber + "'");
     //if (count == 0)
     //{
     //    using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
     //    {
     //        try
     //        {
     //            YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmRfid>(ascmRfid);
     //            tx.Commit();//正确执行提交
     //        }
     //        catch (Exception ex)
     //        {
     //            tx.Rollback();//回滚
     //            YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmRfid)", ex);
     //            throw ex;
     //        }
     //    }
     //}
     //else
     //{
     //    throw new Exception("已经存在员工编号\"" + ascmRfid.name + "\"!");
     //}
 }
コード例 #10
0
ファイル: AscmRfidService.cs プロジェクト: gofixiao/Midea
 public void Save(AscmRfid ascmRfid)
 {
     try
     {
         //int count = YnDaoHelper.GetInstance().nHibernateHelper.GetCount("select count(*) from AscmRfid where docNumber='" + ascmRfid.docNumber + "'");
         //if (count == 0)
         //{
         //    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmRfid");
         //    using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         //    {
         //        try
         //        {
         //            maxId++;
         //            ascmRfid.id = maxId;
         //            YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmRfid);
         //            tx.Commit();//正确执行提交
         //        }
         //        catch (Exception ex)
         //        {
         //            tx.Rollback();//回滚
         //            throw ex;
         //        }
         //    }
         //}
         //else
         //{
         //    throw new Exception("已经存在员工编号\"" + ascmRfid.name + "\"!");
         //}
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("保存失败(Save AscmRfid)", ex);
         throw ex;
     }
 }