public JsonResult CreateVehicleInFactory(VehicleInFactoryMaster vehicleInFactoryMaster)
        {
            try
            {
                vehicleInFactoryMaster.VehicleInFactoryDetails = (IList<VehicleInFactoryDetail>)TempData["vehicleInFactoryDetails"];
                if (vehicleInFactoryMaster.VehicleInFactoryDetails == null || vehicleInFactoryMaster.VehicleInFactoryDetails.Count == 0)
                {
                    throw new BusinessException(@Resources.CUST.VehicleInFactoryMaster.VehicleInFactory_IpNoIsEmpty);
                }

                vehicleInFactoryMgr.CreateVehicleInFactory(vehicleInFactoryMaster);
                SaveSuccessMessage(Resources.CUST.VehicleInFactoryMaster.VehicleInFactory_Created);
                return Json(new { OrderNo = vehicleInFactoryMaster.OrderNo });
            }
            catch (BusinessException ex)
            {
                SaveBusinessExceptionMessage(ex);
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex);
            }
            TempData["vehicleInFactoryDetails"] = vehicleInFactoryMaster.VehicleInFactoryDetails;
            return Json(null);
        }
 public void CreateVehicleInFactory(VehicleInFactoryMaster vehicleInFactoryMaster)
 {
     string hql = "select distinct(r.Plant) from IpMaster as i,Region as r where i.PartyTo = r.Code and i.IpNo in (?";
     IList<object> param = new List<object>();
     param.Add(vehicleInFactoryMaster.VehicleInFactoryDetails[0].IpNo);
     for (int i = 0; i < vehicleInFactoryMaster.VehicleInFactoryDetails.Count(); i++)
     {
         hql += ",?";
         param.Add(vehicleInFactoryMaster.VehicleInFactoryDetails[i].IpNo);
     }
     hql += ")";
     IList<string> plantList = genericMgr.FindAll<string>(hql, param.ToArray());
     if (plantList != null && plantList.Count > 1)
     {
         throw new BusinessException("送货单对应多个工厂");
     }
     vehicleInFactoryMaster.Plant = plantList[0];
     vehicleInFactoryMaster.Status = CodeMaster.VehicleInFactoryStatus.Submit;
     vehicleInFactoryMaster.OrderNo = numberControlMgr.GetVehicleInFactoryNo(vehicleInFactoryMaster);
     genericMgr.Create(vehicleInFactoryMaster);
     foreach (VehicleInFactoryDetail vehicleInFactoryDetail in vehicleInFactoryMaster.VehicleInFactoryDetails)
     {
         vehicleInFactoryDetail.OrderNo = vehicleInFactoryMaster.OrderNo;
         genericMgr.Create(vehicleInFactoryDetail);
     }
 }
 public string CreateVehicleInFactory(VehicleInFactoryMaster vehicleInFactoryMaster)
 {
     try
     {
         vehicleInFactoryMaster.VehicleInFactoryDetails = (IList<VehicleInFactoryDetail>)TempData["vehicleInFactoryDetails"];
         if (vehicleInFactoryMaster.VehicleInFactoryDetails == null || vehicleInFactoryMaster.VehicleInFactoryDetails.Count == 0)
         {
             throw new BusinessException(@Resources.CUST.VehicleInFactoryMaster.VehicleInFactory_IpNoIsEmpty);
         }
    
         vehicleInFactoryMgr.CreateVehicleInFactory(vehicleInFactoryMaster);
         SaveSuccessMessage(@Resources.CUST.VehicleInFactoryMaster.VehicleInFactory_Created);
         return vehicleInFactoryMaster.OrderNo;
     }
     catch (BusinessException ex)
     {
         Response.TrySkipIisCustomErrors = true;
         Response.StatusCode = 500;
         Response.Write(ex.GetMessages()[0].GetMessageString());
         TempData["vehicleInFactoryDetails"] = vehicleInFactoryMaster.VehicleInFactoryDetails;
         return string.Empty;
     }
 }
        public string GetVehicleInFactoryNo(VehicleInFactoryMaster vehicleInFactoryMaster)
        {
            SqlParameter[] parm = new SqlParameter[3];

            parm[0] = new SqlParameter("@Plant", SqlDbType.VarChar, 50);
            parm[0].Value = vehicleInFactoryMaster.Plant;

            parm[1] = new SqlParameter("@Status", SqlDbType.Int);
            parm[1].Value = vehicleInFactoryMaster.Status;

            parm[2] = new SqlParameter("@VehNo", SqlDbType.VarChar, 100);
            parm[2].Direction = ParameterDirection.InputOutput;

            sqlDao.ExecuteStoredProcedure("USP_GetDocNo_VEH", parm);

            return parm[2].Value.ToString();
        }
        public void TryCloseVehicleInFactory(VehicleInFactoryMaster vehicleInFactoryMaster)
        {
            if (vehicleInFactoryMaster.Status != com.Sconit.CodeMaster.VehicleInFactoryStatus.Close)
            {
                this.genericMgr.FlushSession();

                string hql = "select count(*) as counter from VehicleInFactoryDetail where OrderNo = ? and IsClose = ?";
                long counter = genericMgr.FindAll<long>(hql, new object[] { vehicleInFactoryMaster.OrderNo, false })[0];
                if (counter == 0)
                {
                    vehicleInFactoryMaster.Status = com.Sconit.CodeMaster.VehicleInFactoryStatus.Close;
                    vehicleInFactoryMaster.CloseDate = DateTime.Now;
                    vehicleInFactoryMaster.CloseUserId = SecurityContextHolder.Get().Id;
                    vehicleInFactoryMaster.CloseUserName = SecurityContextHolder.Get().FullName;

                    genericMgr.Update(vehicleInFactoryMaster);
                }
                else if(vehicleInFactoryMaster.Status == com.Sconit.CodeMaster.VehicleInFactoryStatus.Submit)
                {
                    vehicleInFactoryMaster.Status = com.Sconit.CodeMaster.VehicleInFactoryStatus.InProcess;
                    genericMgr.Update(vehicleInFactoryMaster);
                }
            }
        }
        private IList<VehicleInFactoryDetail> TryLoadVehicleInFactoryDetailList(VehicleInFactoryMaster vehicleInFactoryMaster)
        {

            if (!string.IsNullOrWhiteSpace(vehicleInFactoryMaster.OrderNo))
            {
                if (vehicleInFactoryMaster.VehicleInFactoryDetails == null)
                {
                    string hql = "from VehicleInFactoryDetail where OrderNo = ?";

                    vehicleInFactoryMaster.VehicleInFactoryDetails = this.genericMgr.FindAll<VehicleInFactoryDetail>(hql, vehicleInFactoryMaster.OrderNo);
                }

                return vehicleInFactoryMaster.VehicleInFactoryDetails;
            }
            else
            {
                return null;
            }

        }