public SystemMessage OrganizationUnitPlanImplementation_Save(OrganizationUnitPlan data) { SystemMessage systemMessage = new SystemMessage(); try { var param = new DynamicParameters(); param.Add("@AutoID", data.AutoID); param.Add("@OrganizationUnitID", data.OrganizationUnitID); param.Add("@CurrencyTypeID", data.CurrencyTypeID); param.Add("@status", data.Status); param.Add("@Comment", data.Comment); param.Add("@Type", data.Type); param.Add("@ContractType", data.ContractType); param.Add("@Year", data.Year); 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("OrganizationUnitPlanImplementation_Save", param); systemMessage.IsSuccess = true; return(systemMessage); } catch (Exception e) { systemMessage.IsSuccess = false; systemMessage.Message = e.ToString(); return(systemMessage); } }
public ActionResult ExportOrganizationUnitPlanImplementationDataError() { DataTable dt = new DataTable("Grid"); dt.Columns.AddRange(new DataColumn[] { new DataColumn(AppRes.OrganazationId), new DataColumn(AppRes.Department), new DataColumn(AppRes.ContractCode), new DataColumn(AppRes.Year), new DataColumn(AppRes.StatusCode), new DataColumn(AppRes.L1), new DataColumn(AppRes.L2), new DataColumn(AppRes.L3), new DataColumn(AppRes.L4), new DataColumn(AppRes.L5), new DataColumn(AppRes.L6), new DataColumn(AppRes.L7), new DataColumn(AppRes.L8), new DataColumn(AppRes.L9), new DataColumn(AppRes.L10), new DataColumn(AppRes.L11), new DataColumn(AppRes.L12), new DataColumn(AppRes.Note), }); dt.Columns[0].DataType = typeof(string); dt.Columns[1].DataType = typeof(string); dt.Columns[2].DataType = typeof(int); dt.Columns[3].DataType = typeof(int); dt.Columns[4].DataType = typeof(int); dt.Columns[5].DataType = typeof(double); dt.Columns[6].DataType = typeof(double); dt.Columns[7].DataType = typeof(double); dt.Columns[8].DataType = typeof(double); dt.Columns[9].DataType = typeof(double); dt.Columns[10].DataType = typeof(double); dt.Columns[11].DataType = typeof(double); dt.Columns[12].DataType = typeof(double); dt.Columns[13].DataType = typeof(double); dt.Columns[14].DataType = typeof(double); dt.Columns[15].DataType = typeof(double); dt.Columns[16].DataType = typeof(double); dt.Columns[17].DataType = typeof(string); List <OrganizationUnitPlan> Data = (List <OrganizationUnitPlan>)Session["data"]; var db = new OrganizationUnitPlan(); int LanguageCode = Global.CurrentUser.CurrentLanguageID; foreach (var item in Data) { dt.Rows.Add(item.OrganizationUnitCode, item.OrganizationUnitName, item.ContractType, item.Year, item.Status, item.M1, item.M2, item.M3, item.M4, item.M5, item.M6, item.M7, item.M8, item.M9, item.M10, item.M11, item.M12, item.Result); } var wb = new XLWorkbook(); wb.Worksheets.Add(dt); byte[] data = null; using (var stream = new MemoryStream()) { wb.SaveAs(stream); data = stream.ToArray(); } Session["data"] = null; return(File(data, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "OrganizationUnitPlanImplementationDataError.xlsx")); }
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 <OrganizationUnitPlan>(); 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())) { var OrganizationUnitPlan = new OrganizationUnitPlan(); OrganizationUnitPlan.AutoID = 0; OrganizationUnitPlan.OrganizationUnitCode = workSheet.Cells[rowIterator, 1].Value == null ? null : workSheet.Cells[rowIterator, 1].Value.ToString(); OrganizationUnitPlan.OrganizationUnitName = workSheet.Cells[rowIterator, 2].Value == null ? null : workSheet.Cells[rowIterator, 2].Value.ToString(); OrganizationUnitPlan.ContractType = workSheet.Cells[rowIterator, 3].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 3].Value.ToString().Trim()) ? 0 : Convert.ToInt32(workSheet.Cells[rowIterator, 3].Value.ToString()); OrganizationUnitPlan.Year = workSheet.Cells[rowIterator, 4].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 4].Value.ToString().Trim()) ? 0 : Convert.ToInt32(workSheet.Cells[rowIterator, 4].Value.ToString()); OrganizationUnitPlan.Status = workSheet.Cells[rowIterator, 5].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 5].Value.ToString().Trim()) ? 10 : Convert.ToInt32(workSheet.Cells[rowIterator, 5].Value.ToString()); OrganizationUnitPlan.M1 = workSheet.Cells[rowIterator, 6].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 6].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 6].Value.ToString()); OrganizationUnitPlan.M2 = workSheet.Cells[rowIterator, 7].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 7].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 7].Value.ToString()); OrganizationUnitPlan.M3 = workSheet.Cells[rowIterator, 8].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 8].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 8].Value.ToString()); OrganizationUnitPlan.M4 = workSheet.Cells[rowIterator, 9].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 9].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 9].Value.ToString()); OrganizationUnitPlan.M5 = workSheet.Cells[rowIterator, 10].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 10].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 10].Value.ToString()); OrganizationUnitPlan.M6 = workSheet.Cells[rowIterator, 11].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 11].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 11].Value.ToString()); OrganizationUnitPlan.M7 = workSheet.Cells[rowIterator, 12].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 12].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 12].Value.ToString()); OrganizationUnitPlan.M8 = workSheet.Cells[rowIterator, 13].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 13].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 13].Value.ToString()); OrganizationUnitPlan.M9 = workSheet.Cells[rowIterator, 14].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 14].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 14].Value.ToString()); OrganizationUnitPlan.M10 = workSheet.Cells[rowIterator, 15].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 15].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 15].Value.ToString()); OrganizationUnitPlan.M11 = workSheet.Cells[rowIterator, 16].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 16].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 16].Value.ToString()); OrganizationUnitPlan.M12 = workSheet.Cells[rowIterator, 17].Value == null || string.IsNullOrEmpty(workSheet.Cells[rowIterator, 17].Value.ToString().Trim()) ? 0 : Convert.ToDouble(workSheet.Cells[rowIterator, 17].Value.ToString()); OrganizationUnitPlan.StatusInput = 0; OrganizationUnitPlan.CreatedBy = Global.CurrentUser.UserID; OrganizationUnitPlan.CreatedOn = DateTime.Now; OrganizationUnitPlan.ModifiedBy = Global.CurrentUser.UserID; OrganizationUnitPlan.ModifiedOn = DateTime.Now; List.Add(OrganizationUnitPlan); } } } var db = new OrganizationUnitPlanImplementation_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.ImPortOrganizationUnitPlanImplementation(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 e) { var SM = new SystemMessage(); SM.IsSuccess = false; SM.Message = AppRes.ErrorFileExcel; return(Content(JsonConvert.SerializeObject(new { SM, }))); } return(View()); }