Exemple #1
0
        public ActionResult CurrentStaffInfo(CurrentStaffDTO dto, Page page)
        {
            var orgInfo = this.CurrentUser.GetUserInfo.OrgInfo;

            if (orgInfo.Count() == 0)
            {
                dto.Plant_Organization_UID = 0;
                dto.BG_Organization_UID    = 0;
            }
            var apiUrl = string.Format("ProductionResourcePlan/QueryCurrentStaffInfoAPI");
            HttpResponseMessage responMessage = APIHelper.APIPostAsync(dto, page, apiUrl);
            var result = responMessage.Content.ReadAsStringAsync().Result;

            return(Content(result, "application/json"));
        }
Exemple #2
0
        public string ImportStaffExcel(HttpPostedFileBase uploadName)
        {
            string errorInfo = string.Empty;
            var    orgInfo   = this.CurrentUser.GetUserInfo.OrgInfo;

            if (orgInfo.Count() == 0)
            {
                errorInfo = "请先分配厂区和Business Group";
                return(errorInfo);
            }

            using (var xlPackage = new ExcelPackage(uploadName.InputStream))
            {
                int iRow      = 2;
                var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault();
                //int totalRows = worksheet.Dimension.End.Row;

                List <CurrentStaffDTO> list = new List <CurrentStaffDTO>();

                //int funcPlantUID = 0;
                while (worksheet.Cells[iRow, 1].Value != null)
                {
                    var productDate  = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, 1].Value);
                    var productPhase = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, 2].Value);
                    var opQty        = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, 3].Value);
                    var monQty       = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, 4].Value);
                    var technicalQty = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, 5].Value);
                    var materialQty  = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, 6].Value);
                    var otherQty     = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, 7].Value);


                    if (string.IsNullOrEmpty(productDate))
                    {
                        errorInfo = "请输入日期";
                        return(errorInfo);
                    }

                    if (string.IsNullOrEmpty(productPhase))
                    {
                        errorInfo = "请输入阶段";
                        return(errorInfo);
                    }

                    if (string.IsNullOrEmpty(opQty))
                    {
                        errorInfo = "请输入OP人力";
                        return(errorInfo);
                    }

                    int validInt = 0;
                    var isInt    = int.TryParse(opQty, out validInt);
                    if (!isInt)
                    {
                        errorInfo = string.Format("第{0}行OP人力必须为整数", iRow);
                        return(errorInfo);
                    }

                    if (string.IsNullOrEmpty(monQty))
                    {
                        errorInfo = "请输入班长";
                        return(errorInfo);
                    }

                    isInt = int.TryParse(monQty, out validInt);
                    if (!isInt)
                    {
                        errorInfo = string.Format("第{0}行班长必须为整数", iRow);
                        return(errorInfo);
                    }

                    if (string.IsNullOrEmpty(technicalQty))
                    {
                        errorInfo = "请输入技术员";
                        return(errorInfo);
                    }
                    isInt = int.TryParse(technicalQty, out validInt);
                    if (!isInt)
                    {
                        errorInfo = string.Format("第{0}行技术员必须为整数", iRow);
                        return(errorInfo);
                    }

                    if (string.IsNullOrEmpty(materialQty))
                    {
                        errorInfo = "请输入物料员";
                        return(errorInfo);
                    }
                    isInt = int.TryParse(materialQty, out validInt);
                    if (!isInt)
                    {
                        errorInfo = string.Format("第{0}行物料员必须为整数", iRow);
                        return(errorInfo);
                    }

                    if (string.IsNullOrEmpty(otherQty))
                    {
                        errorInfo = "请输入其他人力";
                        return(errorInfo);
                    }
                    isInt = int.TryParse(otherQty, out validInt);
                    if (!isInt)
                    {
                        errorInfo = string.Format("第{0}行其他人力必须为整数", iRow);
                        return(errorInfo);
                    }


                    CurrentStaffDTO item = new CurrentStaffDTO();
                    item.Plant_Organization_UID = orgInfo.First().Plant_OrganizationUID.Value;
                    item.BG_Organization_UID    = orgInfo.First().OPType_OrganizationUID.Value;
                    //item.FunPlant_OrganizationUID = funcPlantUID;
                    item.ProductDate         = Convert.ToDateTime(productDate);
                    item.Product_Phase       = productPhase;
                    item.OP_Qty              = Convert.ToInt32(opQty);
                    item.Monitor_Staff_Qty   = Convert.ToInt32(monQty);
                    item.Technical_Staff_Qty = Convert.ToInt32(technicalQty);
                    item.Material_Keeper_Qty = Convert.ToInt32(materialQty);
                    item.Others_Qty          = Convert.ToInt32(otherQty);
                    item.Created_UID         = this.CurrentUser.GetUserInfo.Account_UID;
                    item.Created_Date        = DateTime.Now;
                    item.Modified_UID        = this.CurrentUser.GetUserInfo.Account_UID;
                    item.Modified_Date       = DateTime.Now;
                    item.LanguageID          = PISSessionContext.Current.CurrentWorkingLanguage.System_Language_UID;
                    list.Add(item);
                    iRow++;
                }

                int totalRows = iRow - 2;
                if (list.Distinct().Count() != totalRows)
                {
                    errorInfo = "导入的Excel有重复行";
                    return(errorInfo);
                }

                string json = JsonConvert.SerializeObject(list);


                if (string.IsNullOrEmpty(errorInfo))
                {
                    //检查导入的数据是否存在
                    string api = string.Format("ProductionResourcePlan/CheckImportCurrentStaffExcelAPI");
                    HttpResponseMessage checkResponMessage = APIHelper.APIPostAsync(json, api);
                    var checkResult = checkResponMessage.Content.ReadAsStringAsync().Result;
                    checkResult = checkResult.Replace("\"", "");
                    if (!string.IsNullOrEmpty(checkResult))
                    {
                        errorInfo = checkResult;
                        return(errorInfo);
                    }
                }


                var apiUrl = string.Format("ProductionResourcePlan/ImportCurrentStaffInfoAPI");
                HttpResponseMessage responMessage = APIHelper.APIPostAsync(json, apiUrl);
                var result = responMessage.Content.ReadAsStringAsync().Result;
            }
            return(string.Empty);
        }