public void Delete(AscmDiscreteJobs ascmDiscreteJobs)
 {
     try
     {
         YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmDiscreteJobs>(ascmDiscreteJobs);
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmDiscreteJobs)", ex);
         throw ex;
     }
 }
Example #2
0
        public ContentResult ImportWipDiscreteJobsEditSave(AscmDiscreteJobs ascmDiscreteJobs_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                string userName = string.Empty;
                if (User.Identity.IsAuthenticated)
                {
                    userName = User.Identity.Name;
                }

                AscmDiscreteJobs ascmDiscreteJobs = null;
                if (id.HasValue)
                {
                    ascmDiscreteJobs = AscmDiscreteJobsService.GetInstance().Get(id.Value);
                    ascmDiscreteJobs.modifyUser = userName;
                    ascmDiscreteJobs.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                }

                //if (!string.IsNullOrEmpty(ascmDiscreteJobs_Model.tip))
                ascmDiscreteJobs.tip = ascmDiscreteJobs_Model.tip;

                if (id.HasValue)
                {
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmDiscreteJobs where jobId = '" + ascmDiscreteJobs_Model.jobId + "' 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("已经存在此排产单信息【" + ascmDiscreteJobs_Model.jobId + "】!");
                    AscmDiscreteJobsService.GetInstance().Update(ascmDiscreteJobs);
                }
                jsonObjectResult.result = true;
                jsonObjectResult.message = "";
                jsonObjectResult.id = ascmDiscreteJobs.id.ToString();
                jsonObjectResult.entity = ascmDiscreteJobs;
            }
            catch (Exception ex)
            {
                jsonObjectResult.result = false;
                jsonObjectResult.message = ex.Message;
            }

            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
Example #3
0
        public ContentResult ImportWipDiscreteJobs(HttpPostedFileBase fileImport, AscmDiscreteJobs ascmDiscreteJobs_Model)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            string sError = "";
            DataTable dt = new DataTable();
            int colsCount = 0;
            colsCount = int.TryParse(AscmCommonHelperService.DiscreteJobsImportParam.ToString(), out colsCount) ? colsCount : 8;
            StringBuilder sb = new StringBuilder();

            string userName = string.Empty;
            string userRole = string.Empty;
            if (User.Identity.IsAuthenticated)
            {
                userName = User.Identity.Name;
            }
            userRole = AscmUserInfoService.GetInstance().GetUserRoleName(userName);

            try
            {
                for (int i = 0; i < colsCount; i++)
                {
                    dt.Columns.Add("第" + i.ToString() + "列");
                }

                if (fileImport != null)
                {
                    string fileName = fileImport.FileName;
                    string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();

                    if (fileExtension != ".xls" && fileExtension != ".xlsx")
                        throw new Exception("仅支持Excel-2003|Excel-2007的格式");

                    using (Stream stream = fileImport.InputStream)
                    {
                        NPOI.SS.UserModel.IWorkbook wb = NPOI.SS.UserModel.WorkbookFactory.Create(stream);
                        ISheet sheet = wb.GetSheet("Sheet1");
                        IEnumerator rows = sheet.GetRowEnumerator();
                        while (rows.MoveNext())
                        {
                            DataRow dr = dt.NewRow();
                            NPOI.SS.UserModel.IRow row = (NPOI.SS.UserModel.IRow)rows.Current;
                            if (row.RowNum != 0)
                            {
                                List<NPOI.SS.UserModel.ICell> iCellList = new List<NPOI.SS.UserModel.ICell>();

                                for (int i = 0; i < colsCount; i++)
                                {
                                    NPOI.SS.UserModel.ICell iCell = row.GetCell(i, MissingCellPolicy.CREATE_NULL_AS_BLANK);
                                    iCellList.Add(iCell);
                                }

                                for (int i = 0; i < dt.Columns.Count; i++)
                                {
                                    if (iCellList[i] != null)
                                        dr[i] = iCellList[i].ToString();
                                }
                                dt.Rows.Add(dr);
                            }
                            sb.Append(dr[0].ToString());
                        }
                    }

                    if (dt.Rows.Count > 0)
                    {
                        List<AscmDiscreteJobs> list = new List<AscmDiscreteJobs>();
                        foreach (DataRow dr in dt.Rows)
                        {
                            //判断该排产单是否存在
                            object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmDiscreteJobs where jobId = '" + dr[0].ToString() + "'");
                            if (object1 == null)
                                throw new Exception("导入排产作业查询异常!");
                            int iCount = 0;
                            object object2 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmWipEntities where name = '" + dr[0].ToString() + "'");
                            if (object2 == null)
                                throw new Exception("ERP下载作业查询异常!");
                            int wipEntityId = AscmWipEntitiesService.GetInstance().GetWipEntityId(dr[0].ToString());
                            int iTotal = 0;
                            if ((int.TryParse(object1.ToString(), out iCount) && iCount == 0) && (int.TryParse(object2.ToString(), out iTotal) && iTotal > 0))
                            {
                                //数据赋值
                                AscmDiscreteJobs ascmDiscreteJobs = new AscmDiscreteJobs();
                                int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmDiscreteJobs") + list.Count;
                                ascmDiscreteJobs.id = ++maxId;
                                ascmDiscreteJobs.jobId = dr[0].ToString();
                                ascmDiscreteJobs.jobDate = Convert.ToDateTime(ExcelUtils.ParseDateTime(dr[1].ToString())).Date.ToString("yyyy-MM-dd");
                                ascmDiscreteJobs.jobInfoId = dr[2].ToString();
                                ascmDiscreteJobs.jobDesc = dr[3].ToString();
                                ascmDiscreteJobs.count = Convert.ToInt32(dr[4].ToString());
                                ascmDiscreteJobs.productLine = dr[5].ToString().Substring(0, dr[5].ToString().IndexOf("("));
                                int length = dr[5].ToString().IndexOf("(") + 1;
                                int ilength = dr[5].ToString().IndexOf(")") - dr[5].ToString().IndexOf("(") - 1;
                                ascmDiscreteJobs.sequence = dr[5].ToString().Substring(dr[5].ToString().IndexOf("(") + 1, dr[5].ToString().IndexOf(")") - dr[5].ToString().IndexOf("(") - 1);
                                ascmDiscreteJobs.tip = dr[6].ToString();
                                ascmDiscreteJobs.status = 1;
                                ascmDiscreteJobs.identificationId = ascmDiscreteJobs_Model.identificationId;
                                ascmDiscreteJobs.onlineTime = dr[7].ToString();
                                ascmDiscreteJobs.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                ascmDiscreteJobs.createUser = userName;
                                ascmDiscreteJobs.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                ascmDiscreteJobs.modifyUser = userName;
                                ascmDiscreteJobs.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                ascmDiscreteJobs.workerId = userName;
                                //吴华允于2015年7月28日添加
                                ascmDiscreteJobs.personName = ascmDiscreteJobs_Model.personName;
                                string dateTime = DateTime.Now.Date.ToString("yyyy-MM-dd");
                                int maxWhich = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(which) from AscmDiscreteJobs where workerId = '" + userName + "' and time like '" + dateTime + "%' and status = 2");
                                ascmDiscreteJobs.which = ++maxWhich;
                                ascmDiscreteJobs.wipEntityId = wipEntityId;

                                list.Add(ascmDiscreteJobs);
                            }
                            else if ((int.TryParse(object1.ToString(), out iCount) && iCount > 0) && (int.TryParse(object2.ToString(), out iTotal) && iTotal > 0))
                            {
                                sError += "已存在该排产作业号[" + dr[0].ToString() + "] <br />";
                            }
                            else if ((int.TryParse(object1.ToString(), out iCount) && iCount == 0) && (int.TryParse(object2.ToString(), out iTotal) && iTotal == 0))
                            {
                                if (!string.IsNullOrEmpty(dr[0].ToString()))
                                    sError += "不存在ERP作业号[" + dr[0].ToString() + "] <br />";
                            }
                        }
                        if (list != null && list.Count > 0)
                        {
                            AscmDiscreteJobsService.GetInstance().Save(list);
                            jsonObjectResult.result = true;
                        }
                        jsonObjectResult.message = sError;
                    }
                }
            }
            catch (Exception ex)
            {
                jsonObjectResult.result = false;
                jsonObjectResult.message = ex.Message;
            }

            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
 public void Update(AscmDiscreteJobs ascmDiscreteJobs)
 {
     try
     {
         using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         {
             try
             {
                 YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmDiscreteJobs>(ascmDiscreteJobs);
                 tx.Commit();//正确执行提交
             }
             catch (Exception ex)
             {
                 tx.Rollback();//回滚
                 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmDiscreteJobs)", ex);
                 throw ex;
             }
         }
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Save AscmDiscreteJobs)", ex);
         throw ex;
     }
 }
        public ContentResult DiscreteJobsSave(HttpPostedFileBase fileLoad, AscmDiscreteJobs ascmDiscreteJobs_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            DataTable dt = null;
            StringBuilder sb = new StringBuilder();
            try
            {
                string userName = string.Empty;
                string userRole = string.Empty;
                if (User.Identity.IsAuthenticated)
                {
                    userName = User.Identity.Name;
                    List<YnRole> listYnRole = YnRoleService.GetInstance().GetListInUser(userName);
                    foreach (YnRole role in listYnRole)
                    {
                        if (role.name == "总装排产员" || role.name == "电装排产员")
                        {
                            userRole = role.name;
                        }
                    }
                }

                AscmDiscreteJobs ascmDiscreteJobs = null;
                //string fileUrl = "";
                if (fileLoad != null)
                {
                    string fileName = fileLoad.FileName;
                    string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();

                    if (fileExtension != ".xls")
                        throw new Exception("仅支持Excel-2003的格式");

                    #region //上传Excel文件
                    //string serverPath = Server.MapPath(Request.ApplicationPath);
                    //string serverDirectory = System.IO.Path.Combine(serverPath, "_data\\UnloadingExcelFile");
                    //if (!Directory.Exists(serverDirectory))
                    //{
                    //    Directory.CreateDirectory(serverDirectory);
                    //}
                    //string serverFileName = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtension;
                    //string serverFilePath = System.IO.Path.Combine(serverDirectory, serverFileName);

                    //fileLoad.SaveAs(serverFilePath);

                    //fileUrl = (Request.ApplicationPath == "/" ? "" : Request.ApplicationPath) + "/_data/UnloadingExcelFile/" + serverFileName;
                    //通过文件流转换byte[]最终转换为读取Excel文件数据的内存流
                    //FileStream fileStream = new FileStream(fileLoad.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    //byte[] bytes = new byte[fileStream.Length];
                    //fileStream.Read(bytes, 0, bytes.Length);
                    //fileStream.Close();
                    #endregion

                    Stream stream = fileLoad.InputStream;
                    byte[] bytes = new byte[fileLoad.ContentLength];
                    stream.Read(bytes, 0, bytes.Length);
                    stream.Close();

                    try
                    {
                        using (MemoryStream memoryStream = new MemoryStream(bytes))
                        {
                            dt = ExcelUtils.TranslateToTable(memoryStream, "sheet1");
                        }

                        //int icount = dt.Rows.Count;  //得到Excel的行数

                        if (dt.Rows.Count > 0)
                        {
                            List<string> ListString = new List<string>();
                            foreach (DataRow dr in dt.Rows)
                            {
                                //判断该排产单是否存在
                                object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmDiscreteJobs where jobId = '" + dr[0].ToString() + "'");
                                if (object1 == null)
                                    throw new Exception("查询异常!");
                                int iCount = 0;
                                object object2 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmWipEntities where name = '" + dr[0].ToString() + "'");
                                if (object2 == null)
                                    throw new Exception("查询异常!");
                                int iTotal = 0;
                                if ((int.TryParse(object1.ToString(), out iCount) && iCount == 0) && (int.TryParse(object2.ToString(), out iTotal) && iTotal > 0))
                                {
                                    //数据赋值
                                    ascmDiscreteJobs = new AscmDiscreteJobs();
                                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmDiscreteJobs");
                                    ascmDiscreteJobs.id = ++maxId;
                                    ascmDiscreteJobs.jobId = dr[0].ToString();
                                    ascmDiscreteJobs.jobDate = Convert.ToDateTime(ExcelUtils.ParseDateTime(dr[1].ToString())).Date.ToString("yyyy-MM-dd");
                                    ascmDiscreteJobs.jobInfoId = dr[2].ToString();
                                    ascmDiscreteJobs.jobDesc = dr[3].ToString();
                                    ascmDiscreteJobs.count = Convert.ToInt32(dr[4].ToString());
                                    ascmDiscreteJobs.productLine = dr[5].ToString().Substring(0, dr[5].ToString().IndexOf("("));
                                    int length = dr[5].ToString().IndexOf("(") + 1;
                                    int ilength = dr[5].ToString().IndexOf(")") - dr[5].ToString().IndexOf("(") - 1;
                                    ascmDiscreteJobs.sequence = dr[5].ToString().Substring(dr[5].ToString().IndexOf("(") + 1, dr[5].ToString().IndexOf(")") - dr[5].ToString().IndexOf("(") - 1);
                                    ascmDiscreteJobs.tip = dr[6].ToString();
                                    ascmDiscreteJobs.status = 1;
                                    if (userRole == "总装排产员")
                                    {
                                        ascmDiscreteJobs.identificationId = 1;
                                    }
                                    else if (userRole == "电装排产员")
                                    {
                                        ascmDiscreteJobs.identificationId = 2;
                                    }
                                    else
                                    {
                                        ascmDiscreteJobs.identificationId = 0;
                                    }

                                    if (ascmDiscreteJobs.identificationId == 2)
                                    {
                                        ascmDiscreteJobs.onlineTime = "上午";
                                    }
                                    else
                                    {
                                        ascmDiscreteJobs.onlineTime = dr[7].ToString();
                                    }
                                    ascmDiscreteJobs.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                    ascmDiscreteJobs.createUser = userName;
                                    ascmDiscreteJobs.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                    ascmDiscreteJobs.modifyUser = userName;
                                    ascmDiscreteJobs.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                                    ascmDiscreteJobs.workerId = userName;
                                    string dateTime = DateTime.Now.Date.ToString("yyyy-MM-dd");
                                    int maxWhich = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(which) from AscmDiscreteJobs where workerId = '" + userName + "' and time like '" + dateTime + "%' and status = 2");
                                    ascmDiscreteJobs.which = ++maxWhich;

                                    AscmDiscreteJobsService.GetInstance().Save(ascmDiscreteJobs);
                                }
                                else if ((int.TryParse(object1.ToString(), out iCount) && iCount > 0) || (int.TryParse(object2.ToString(), out iTotal) && iTotal == 0))
                                {
                                    ListString.Add(dr[0].ToString());
                                }
                            }
                            if (ListString.Count > 0)
                            {
                                foreach (string item in ListString)
                                {
                                    if (!string.IsNullOrEmpty(sb.ToString()))
                                        sb.Append(",");
                                    sb.Append(item.ToString());
                                }
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                jsonObjectResult.result = true;
                jsonObjectResult.message = sb.ToString();
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
 public AscmDiscreteJobs containsJob(List<AscmDiscreteJobs> listJobs, AscmDiscreteJobs job)
 {
     if (listJobs.Count == 0)
         return null;
     foreach (AscmDiscreteJobs item in listJobs)
     {
         if (item.jobId == job.jobId)
             return item;
     }
     return null;
 }