예제 #1
0
        public static MaterialToolViewModel SaveMaterialTool(MaterialToolModel model, UserLoginInfo loginUser)
        {
            var result = new MaterialToolViewModel()
            {
                IsSuccess = true
            };

            try
            {
                //add
                if (model.Id == 0)
                {
                    model.MTIsValid         = 1;
                    model.MTCreateUserNo    = loginUser.JobNum;
                    model.MTCreateUserName  = loginUser.UserName;
                    model.MTCreateTime      = DateTime.Now;
                    model.MTOperateUserNo   = loginUser.JobNum;
                    model.MTOperateUserName = loginUser.UserName;
                    model.MTOperateTime     = DateTime.Now;
                    model.Id       = _materialDal.InsertMaterialTool(model);
                    result.Message = EncryptHelper.DesEncrypt(model.Id.ToString()); //TODO
                    result.data    = model;
                }
                else
                {
                    //Update
                    model.MTOperateUserNo   = loginUser.JobNum;
                    model.MTOperateUserName = loginUser.UserName;
                    model.MTOperateTime     = DateTime.Now;
                    _materialDal.UpdateMaterialTool(model);
                    result.Message = EncryptHelper.DesEncrypt(model.Id.ToString()); //TODO
                    result.data    = model;
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 导入
        /// 创建人:wq
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ActionResult ImportMaterialTool(int type)
        {
            var result = new ImportUploadResult()
            {
                IsSuccess = false
            };
            var                invalidlist = new List <InvalidData>();
            StringBuilder      strbuild    = new StringBuilder();
            string             FileName;
            string             savePath;
            HttpPostedFileBase file = Request.Files["file"];

            if (file == null || file.ContentLength <= 0)
            {
                result.Message = "please choose file";
                return(Content(JsonHelper.JsonSerializer(result)));
            }
            else
            {
                string fileName   = Path.GetFileName(file.FileName);
                int    filesize   = file.ContentLength;                         //获取上传文件的大小单位为字节byte
                string fileEx     = Path.GetExtension(fileName);                //获取上传文件的扩展名
                string NoFileName = Path.GetFileNameWithoutExtension(fileName); //获取无扩展名的文件名
                int    Maxsize    = 4000 * 1024;                                //定义上传文件的最大空间大小为4M
                string FileType   = ".xls,.xlsx";                               //定义上传文件的类型字符串

                FileName = NoFileName + fileEx;
                if (!FileType.Contains(fileEx))
                {
                    result.Message = "please upload .xls and .xlsx";
                    return(Content(JsonHelper.JsonSerializer(result)));
                }
                if (filesize >= Maxsize)
                {
                    result.Message = string.Format("file size can't big than {0}", Maxsize);
                    return(Content(JsonHelper.JsonSerializer(result)));
                }
                string path = Server.MapPath("~/App_Data/uploads");
                savePath = Path.Combine(path, FileName);
                file.SaveAs(savePath);
            }

            string strConn;

            strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + savePath + ";Extended Properties=Excel 12.0;";
            using (OleDbConnection conn = new OleDbConnection(strConn))
            {
                conn.Open();
                OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Sheet1$]", strConn);
                DataSet          myDataSet = new DataSet();
                try
                {
                    myCommand.Fill(myDataSet, "ExcelInfo");
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                    return(Content(JsonHelper.JsonSerializer(result)));
                }
                DataTable table = myDataSet.Tables["ExcelInfo"].DefaultView.ToTable();

                try
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        var model = new MaterialToolModel();
                        model.MTSapPN            = table.Rows[i][0].ToString();
                        model.MTSapQuantity      = table.Rows[i][1].ToString();
                        model.MTSapLibrary       = table.Rows[i][2].ToString();
                        model.MTToolNo           = table.Rows[i][3].ToString();
                        model.MTProductName      = table.Rows[i][4].ToString();
                        model.MTStatus           = table.Rows[i][5].ToString();
                        model.MTToolLibrary      = table.Rows[i][6].ToString();
                        model.MTOutlineDimension = table.Rows[i][7].ToString();
                        model.MTQuality          = table.Rows[i][8].ToString();
                        model.MTCustomerPN       = table.Rows[i][9].ToString();
                        model.MTSapProductName   = table.Rows[i][10].ToString();
                        model.MTBelong           = table.Rows[i][11].ToString();
                        model.MTCustomerNo       = table.Rows[i][12].ToString();
                        model.MTToolSupplier     = table.Rows[i][13].ToString();
                        model.MTToolSupplierNo   = table.Rows[i][14].ToString();
                        model.MTProductDate      = table.Rows[i][15].ToString();
                        model.MTCavity           = table.Rows[i][16].ToString();

                        var inserResult = MaterialBusiness.SaveMaterialTool(model, LoginUser);
                    }
                    result.invalidData = invalidlist;
                    result.IsSuccess   = true;
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                    return(Content(JsonHelper.JsonSerializer(result)));
                }
                conn.Close();
            }
            return(Content(JsonHelper.JsonSerializer(result)));
        }
예제 #3
0
        public ActionResult MaterialToolOperate(MaterialToolModel model)
        {
            var result = MaterialBusiness.SaveMaterialTool(model, this.LoginUser);

            return(Json(result));
        }