Beispiel #1
0
        public SystemMessage StaffPlanImplementation_Save(StaffPlan data)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var param = new DynamicParameters();
                param.Add("@AutoID", data.AutoID);
                param.Add("@UserID", data.UserID);
                param.Add("@OrganizationUnitID", data.DS_OrganizationUnitID);
                param.Add("@CurrencyTypeID", data.CurrencyTypeID);
                param.Add("@status", data.Status);
                param.Add("@Comment", data.Comment);
                param.Add("@Type", data.Type);
                param.Add("@Year", data.Year);
                param.Add("@ContractType", data.ContractType);
                param.Add("@M1", data.M1);
                param.Add("@M2", data.M2);
                param.Add("@M3", data.M3);
                param.Add("@M4", data.M4);
                param.Add("@M5", data.M5);
                param.Add("@M6", data.M6);
                param.Add("@M7", data.M7);
                param.Add("@M8", data.M8);
                param.Add("@M9", data.M9);
                param.Add("@M10", data.M10);
                param.Add("@M11", data.M11);
                param.Add("@M12", data.M12);
                param.Add("@CreatedBy", data.CreatedBy);
                param.Add("@CreatedOn", data.CreatedOn);
                param.Add("@ModifiedBy", data.CreatedBy);
                param.Add("@ModifiedOn", data.CreatedOn);
                UnitOfWork.ProcedureExecute("StaffPlanImplementation_Save", param);
                systemMessage.IsSuccess = true;
                return(systemMessage);
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }
Beispiel #2
0
        public ActionResult ImportExcel()
        {
            try
            {
                if (Request != null)
                {
                    HttpPostedFileBase file = Request.Files["file-0"];
                    if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                    {
                        string fileName        = file.FileName;
                        string fileContentType = file.ContentType;
                        byte[] fileBytes       = new byte[file.ContentLength];
                        var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                        var    List            = new List <StaffPlan>();

                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfCol      = workSheet.Dimension.End.Column;
                            var noOfRow      = workSheet.Dimension.End.Row;

                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                if (workSheet.Cells[rowIterator, 1].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 1].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 2].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 2].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 3].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 3].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 4].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 4].Value.ToString().Trim()) || workSheet.Cells[rowIterator, 5].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 5].Value.ToString().Trim()) || workSheet.Cells[rowIterator, 6].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 6].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 7].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 7].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 8].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 8].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 9].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 9].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 10].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 10].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 11].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 11].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 12].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 12].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 13].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 13].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 14].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 14].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 15].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 15].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 16].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 16].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 17].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 17].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 18].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 18].Value.ToString().Trim()) ||
                                    workSheet.Cells[rowIterator, 19].Value != null && !string.IsNullOrEmpty(workSheet.Cells[rowIterator, 19].Value.ToString().Trim()))
                                {
                                    var StaffPlan = new StaffPlan();
                                    StaffPlan.AutoID               = 0;
                                    StaffPlan.StaffCode            = workSheet.Cells[rowIterator, 1].Value == null ? null : workSheet.Cells[rowIterator, 1].Value.ToString();
                                    StaffPlan.StaffName            = workSheet.Cells[rowIterator, 2].Value == null ? null : workSheet.Cells[rowIterator, 2].Value.ToString();
                                    StaffPlan.OrganizationUnitCode = workSheet.Cells[rowIterator, 3].Value == null ? null : workSheet.Cells[rowIterator, 3].Value.ToString();
                                    StaffPlan.OrganizationUnitName = workSheet.Cells[rowIterator, 4].Value == null ? null : workSheet.Cells[rowIterator, 4].Value.ToString();
                                    StaffPlan.ContractType         = workSheet.Cells[rowIterator, 5].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 5].Value.ToString().Trim()) ? 0 : Convert.ToInt32(workSheet.Cells[rowIterator, 5].Value.ToString());
                                    StaffPlan.Year        = workSheet.Cells[rowIterator, 6].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 6].Value.ToString().Trim()) ? 0 : Convert.ToInt32(workSheet.Cells[rowIterator, 6].Value.ToString());
                                    StaffPlan.Status      = workSheet.Cells[rowIterator, 7].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 7].Value.ToString().Trim()) ? 10 : Convert.ToInt32(workSheet.Cells[rowIterator, 7].Value.ToString());
                                    StaffPlan.M1          = workSheet.Cells[rowIterator, 8].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 8].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 8].Value.ToString());
                                    StaffPlan.M2          = workSheet.Cells[rowIterator, 9].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 9].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 9].Value.ToString());
                                    StaffPlan.M3          = workSheet.Cells[rowIterator, 10].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 10].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 10].Value.ToString());
                                    StaffPlan.M4          = workSheet.Cells[rowIterator, 11].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 11].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 11].Value.ToString());
                                    StaffPlan.M5          = workSheet.Cells[rowIterator, 12].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 12].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 12].Value.ToString());
                                    StaffPlan.M6          = workSheet.Cells[rowIterator, 13].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 13].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 13].Value.ToString());
                                    StaffPlan.M7          = workSheet.Cells[rowIterator, 14].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 14].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 14].Value.ToString());
                                    StaffPlan.M8          = workSheet.Cells[rowIterator, 15].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 15].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 15].Value.ToString());
                                    StaffPlan.M9          = workSheet.Cells[rowIterator, 16].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 16].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 16].Value.ToString());
                                    StaffPlan.M10         = workSheet.Cells[rowIterator, 17].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 17].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 17].Value.ToString());
                                    StaffPlan.M11         = workSheet.Cells[rowIterator, 18].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 18].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 18].Value.ToString());
                                    StaffPlan.M12         = workSheet.Cells[rowIterator, 19].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 19].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 19].Value.ToString());
                                    StaffPlan.StatusInput = 0;
                                    StaffPlan.CreatedBy   = Global.CurrentUser.UserID;
                                    StaffPlan.ModifiedBy  = Global.CurrentUser.UserID;
                                    StaffPlan.CreatedOn   = DateTime.Now;
                                    StaffPlan.ModifiedOn  = DateTime.Now;
                                    List.Add(StaffPlan);
                                }
                            }
                        }
                        var           db        = new StaffPlanImplementation_DAL();
                        SystemMessage SM        = new SystemMessage();
                        bool          IsSuccess = true;
                        if (List.Count() <= 0)
                        {
                            SM.IsSuccess = false;
                            SM.Message   = AppRes.ErrorNoHasData;
                            return(Content(JsonConvert.SerializeObject(new
                            {
                                SM
                            })));
                        }
                        var result = db.ImPortStaffPlanImplementation(List, out IsSuccess);
                        if (result.Count() > 0)
                        {
                            Session["data"] = result;
                        }
                        if (IsSuccess == true)
                        {
                            SM.IsSuccess = true;
                            SM.Message   = AppRes.Success;
                        }
                        else
                        {
                            SM.IsSuccess = false;
                            SM.Message   = AppRes.ErrorImportOrganizationUnitPlanImplementation;
                        }
                        return(Content(JsonConvert.SerializeObject(new
                        {
                            result,
                            SM
                        })));
                    }
                }
            }
            catch (Exception)
            {
                var SM = new SystemMessage();
                SM.IsSuccess = false;
                SM.Message   = AppRes.ErrorFileExcel;
                return(Content(JsonConvert.SerializeObject(new
                {
                    SM,
                })));
            }

            return(View());
        }