Пример #1
0
        public ActionResult Add(Base_ProductionLine model)
        {
            model.RowState = 1;
            model.Updater  = model.Creater = CurrentUser.Name;

            var query = QueryCondition.Instance;

            query.AddEqual("GoodNo", model.GoodNo);
            query.AddEqual("ProLineNo", model.ProLineNo);
            query.AddEqual("RowState", "1");
            if (model.Id > 0)
            {
                query.AddNotEqual("Id", model.Id.ToString());
            }
            if (_productionLineBizService.GetAllDomain(query).Count > 0)
            {
                ViewBag.GoodList = Smart.Instance.Base_GoodsBizService.GetGoodName(QueryCondition.Instance.AddEqual("RowState", "1"));
                ViewBag.Error    = string.Format("已经存在相同的生产线:{1},产品编号:{0},请重新填写", model.ProLineNo, model.GoodNo);
                return(View(model));
            }
            string newProCapacityDesc;
            var    proCapacityDescList = GetCapacityList(model.ProCapacityDesc, out newProCapacityDesc);

            if (proCapacityDescList.Count == 0)
            {
                ViewBag.GoodList = Smart.Instance.Base_GoodsBizService.GetGoodName(QueryCondition.Instance.AddEqual("RowState", "1"));
                ViewBag.Error    = string.Format("人员配置及每小时产出,解析出错,规则:*人*件/H", model.ProLineNo, model.GoodNo);
                return(View(model));
            }


            if (model.Id == 0)
            {
                int mainId = _productionLineBizService.AddGetId(model);
                //解析人员配置及每小时产出 列:7人75件/H,6人64件/H,5人53件/H
                foreach (var item in proCapacityDescList)
                {
                    item.ProLineId = mainId;
                    _productionLinesBizService.Add(item);
                }

                ViewBag.Error = "1";
                return(RedirectToAction("Add", "ProductionLine", new { Error = 1 }));
            }
            ViewBag.Error = "1";
            _productionLineBizService.Update(model);
            _productionLinesBizService.DeleteByMainId(model.Id);
            foreach (var item in proCapacityDescList)
            {
                item.ProLineId = model.Id;
                _productionLinesBizService.Add(item);
            }
            return(RedirectToAction("Index", "ProductionLine"));
        }
Пример #2
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="Error"></param>
        /// <returns></returns>
        public ActionResult Add(int?Id, string Error)
        {
            ViewBag.GoodList = Smart.Instance.Base_GoodsBizService.GetGoodName(QueryCondition.Instance.AddEqual("RowState", "1"));
            ViewBag.Error    = Error;
            var model = new Base_ProductionLine();

            if (Id.HasValue)
            {
                var query = QueryCondition.Instance.AddEqual("Id", Id.Value.ToString());
                model = _productionLineBizService.GetAllDomain(query).FirstOrDefault();
            }
            AddOrUpdateBaseInfo(model);
            return(View(model));
        }
Пример #3
0
        /// <summary>
        /// 重载 解析Excel
        /// </summary>
        /// <param name="fileAddress"></param>
        /// <returns></returns>
        public override string LoadExcel(string fileAddress)
        {
            int    rowIndex = 2;
            string error    = "success";

            try
            {
                string strConn;
                strConn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + fileAddress + "; Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                DataTable sheetNames = conn.GetOleDbSchemaTable
                                           (OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

                foreach (DataRow rowTable in sheetNames.Rows)
                {
                    string sheetName = rowTable["TABLE_NAME"].ToString();
                    using (conn = new OleDbConnection(strConn))
                    {
                        conn.Open();
                        OleDbCommand objCommand = new OleDbCommand(string.Format("select * from [" + sheetName + "]"), conn);

                        using (OleDbDataReader dataReader = objCommand.ExecuteReader())
                        {
                            while (dataReader.Read())
                            {
                                if (dataReader.FieldCount != 5)
                                {
                                    error = "解析错误,Excel 列头必须是5列,请下载模板 进行对比!";
                                    break;
                                }

                                var model = new Base_ProductionLine();
                                model.ProLineNo = dataReader[0].ToString();
                                model.GoodNo    = dataReader[1].ToString();
                                //model.GoodName = dataReader[2].ToString();
                                model.ProCapacityDesc = dataReader[2].ToString();

                                if (!(dataReader[3] is DBNull) && dataReader[3] != null)
                                {
                                    model.BoxNum = Convert.ToInt32(dataReader[3]);
                                }
                                if (!(dataReader[4] is DBNull) && dataReader[4] != null)
                                {
                                    model.LineMins = Convert.ToInt32(dataReader[4]);
                                }
                                model.ProShift  = 0;
                                model.PCS       = 0;
                                model.StandPers = 0;
                                model.MinProNum = 0;

                                model.Updater  = model.Creater = CurrentUser.Name;
                                model.RowState = 1;
                                var query = QueryCondition.Instance;
                                query.AddEqual("GoodNo", model.GoodNo);
                                query.AddEqual("ProLineNo", model.ProLineNo);
                                query.AddEqual("RowState", "1");

                                string newProCapacityDesc;
                                var    proCapacityDescList = GetCapacityList(model.ProCapacityDesc, out newProCapacityDesc);
                                if (newProCapacityDesc == "")
                                {
                                    error = "Excel解析错误,成功" + (rowIndex - 1) + "条,错误行号:" + rowIndex + ",人员配置及每小时产出,解析出错,规则:*人*件/H,请检查 数据格式。";
                                    break;
                                }
                                model.ProCapacityDesc = newProCapacityDesc;
                                var id = _productionLineBizService.GetId(query);
                                if (id > 0)
                                {
                                    model.Id = id;
                                    _productionLineBizService.Update(model);
                                    _productionLinesBizService.DeleteByMainId(model.Id);
                                }
                                else
                                {
                                    model.Id = _productionLineBizService.AddGetId(model);
                                }
                                //解析人员配置及每小时产出 列:7人75件/H,6人64件/H,5人53件/H
                                foreach (var item in proCapacityDescList)
                                {
                                    item.ProLineId = model.Id;
                                    _productionLinesBizService.Add(item);
                                }

                                rowIndex++;
                            }
                        }
                        conn.Close();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                error = "Excel解析错误,成功" + (rowIndex - 1) + "条,错误行号:" + rowIndex + ",请检查 数据格式。";
                LogHelper.WriteLog("产线导入错误", ex);
            }
            return(error);
        }