/// <summary>
        /// Use with the xml file contains paras elements
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public ActionResult ImportExcel(FileUploadModel model)
        {
            //Test run time upload excel
            //DateTime timeFinish = DateTime.UtcNow;
            //DateTime timeStart = DateTime.UtcNow;
            //TimeSpan timeSpan = new TimeSpan();
            //timeStart = DateTime.Parse(DateTime.Now.ToString("h:mm:ss tt"));
            this.GetLanguage();
            try
            {
                //--------------------GET XML CONFIG -----------------------------------------

                this.SetConnectionDB();
                EVNImporterServices services    = new EVNImporterServices(oracleConnection, DBConnection);
                List <string>       lstCellName = new List <string>();
                string     xmlFilePath          = this.CONFIG_FOLDER + "\\excel_format_" + model.PermissionId.ToString() + ".xml";
                ExcelModel lstColumns           = services.GetXMLConfig(xmlFilePath);

                //************************** UPLOAD FILE TO THE UPLOAD FOLDER***********************************************

                string excelfilename = BI_Project.Helpers.Utility.APIStringHelper.GenerateId() + Path.GetExtension(model.FileObj.FileName);

                //string excelFilePath = System.Web.Hosting.HostingEnvironment.MapPath(this.EXCEL_UPLOAD_FOLDER) + lstColumns.FolderUploadedDirectory + "/" + excelfilename;
                string excelFilePath = System.Web.Hosting.HostingEnvironment.MapPath(this.EXCEL_UPLOAD_FOLDER) + lstColumns.FolderUploadedDirectory + "\\" + excelfilename;
                model.FileObj.SaveAs(excelFilePath);

                //************************ INSERT DATA TO DATABASE ********************
                int userid       = (int)Session[this.SESSION_NAME_USERID];
                int uploadRoleId = model.PermissionId;

                services.ImportPLDatabase(userid, excelFilePath, uploadRoleId, lstColumns, excelfilename);

                //services.Import2Database(userid, excelFilePath)
                if (services.ERROR != null)
                {
                    throw new Exception(services.ERROR);
                }

                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.success");

                Session["msg_code"] = 1;

                //timeFinish = DateTime.Parse(DateTime.Now.ToString("h:mm:ss tt"));

                //timeSpan = timeFinish.Subtract(timeStart);

                //FileHelper.SaveFile(timeSpan, this.LOG_FOLDER + "/TIMESPAN" + this.GetType().ToString() + APIStringHelper.GenerateFileId() + ".txt");
            }

            catch (Exception ex)
            {
                //FileHelper.SaveFile(new { ERROR = ex }, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + APIStringHelper.GenerateFileId() + ".txt");
                ERRORS = ex.Message;
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.error") + " Lỗi " + ex.Message;

                Session["msg_code"] = -1;
            }

            return(RedirectToAction("Index/" + model.PermissionId));
        }
        public ActionResult Import(FileUploadModel model)
        {
            this.GetLanguage();

            //DECLARE PAGE MODEL

            try
            {
                //************************** CHECK PERMISSION **************************
                this.SetConnectionDB();

                //var test = model.FileObj;

                //************************** GET CONFIG
                EVNImporterServices services = new EVNImporterServices(oracleConnection, DBConnection);
                string                tablename = "", sheetActive = "", uploadFolder = "", fileNativeName = "";
                string                note = "", helpDocumentPath = "";
                int                   startRow = 0, numberRow = 0, numberCell = 0;
                List <string>         lstCellName = new List <string>();
                string                xmlFilePath = this.CONFIG_FOLDER + "\\excel_format_" + model.PermissionId.ToString() + ".xml";
                List <MappingExcelDB> lstColumns  = services.GetColumnList(xmlFilePath, ref uploadFolder, ref tablename,
                                                                           ref startRow, ref sheetActive, ref helpDocumentPath, ref note, ref fileNativeName); //, ref numberRow, ref numberCell, ref lstCellName



                //************************** UPLOAD FILE TO THE UPLOAD FOLDER***********************************************
                string excelfilename = BI_Project.Helpers.Utility.APIStringHelper.GenerateId(model.currentyear, model.currentyear) + Path.GetExtension(model.FileObj.FileName);

                string excelFilePath = System.Web.Hosting.HostingEnvironment.MapPath(this.EXCEL_UPLOAD_FOLDER) + uploadFolder + "/" + excelfilename;
                model.FileObj.SaveAs(excelFilePath);

                //************************ INSERT DATA TO DATABASE ********************

                int userid       = (int)Session[this.SESSION_NAME_USERID];
                int uploadRoleId = model.PermissionId;
                int currentYear  = model.currentyear;
                //services.Import2Database(userid,excelFilePath, tablename, startRow, sheetActive,helpDocumentPath,
                //    note,fileNativeName,fileNativeName,uploadRoleId, lstColumns,excelfilename);
                services.ImportToDatabase(currentYear, userid, excelFilePath, tablename, startRow, sheetActive, helpDocumentPath,
                                          note, fileNativeName, fileNativeName, uploadRoleId, lstColumns, excelfilename); //, numberRow, numberCell, lstCellName
                if (services.ERROR != null)
                {
                    throw new Exception(services.ERROR);
                }

                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.success");

                Session["msg_code"] = 1;
            }
            catch (Exception ex)
            {
                FileHelper.SaveFile(new { ERROR = ex }, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + APIStringHelper.GenerateFileId() + ".txt");
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.error");

                Session["msg_code"] = -1;
            }

            return(RedirectToAction("Index/" + model.PermissionId));
        }
Example #3
0
        public ActionResult UploadTableData(BlockDataRowUploadModel model)
        {
            if (null == Session[this.SESSION_NAME_USERID])
            {
                return(RedirectToAction("Login", "Home"));
            }
            if (Session["IsAdmin"] == null || (bool)Session["IsAdmin"] == false)
            {
                return(RedirectToAction("Logout", "Home"));
            }

            this.GetLanguage();

            try
            {
                int output = 0;
                this.SetConnectionDB();
                EVNImporterServices services = new EVNImporterServices(oracleConnection, DBConnection);
                output = services.ExecuteDataTable(model.Month, model.Year, model.File, model.DataString);
                if (output == 0)
                {
                    Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.success");

                    Session["msg_code"] = 1;
                }
                else
                {
                    if (services.ERROR != null)
                    {
                        throw new Exception(services.ERROR);
                    }
                    //Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.error") + " Lỗi " + services.ERROR.ToString();
                    Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.error") + " Lỗi dữ liệu nhập vào.";

                    Session["msg_code"] = -1;
                }
            }
            catch (Exception ex)
            {
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_upload_excel.error") + " Lỗi dữ liệu nhập vào. ";

                Session["msg_code"] = -1;
            }


            if (model.Type == 1)
            {
                var jsonData = new
                {
                    rows = JsonConvert.DeserializeObject <List <object> >(model.DataString)
                };

                return(Json(jsonData, JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("AddDNTData"));
        }
Example #4
0
        public ActionResult Delete()
        {
            if (Session["IsAdmin"] is false)
            {
                return(RedirectToAction("Logout", "Home"));
            }
            string id = this.HttpContext.Request["id"];

            Logging.WriteToLog(this.GetType().ToString() + "-delete(), id=" + id, LogType.Access);
            int output = 0;

            try
            {
                this.SetConnectionDB();



                UserServices services = new UserServices(this.DBConnection);

                output = services.Delete(Int32.Parse(id));
                if (services.ERROR != null)
                {
                    throw new Exception(services.ERROR);
                }
            }
            catch (Exception ex)
            {
                this.ERRORS = ex.ToString();
                FileHelper.SaveFile(ex, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + APIStringHelper.GenerateFileId() + ".txt");
                output = -2;
            }
            ////*************************************XU LY VAN DE THONG BAO THANH CONG HAY THAT BAI********************
            this.GetLanguage();
            if (output > 0)
            {
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_list.success_delete");
            }
            else
            {
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "commons.messages.ServerError");
            }
            Session["msg_code"] = output;
            return(RedirectToAction("List"));
        }
        public void SetMessageText(BlockLanguageModel blockLanguage)
        {
            //string output = null;
            try
            {
                if (Session["msgtype"] != null)
                {
                    int msgType = Int32.Parse(Session["msgtype"].ToString());
                    ViewBag.Message = blockLanguage.GetMessage(msgType);

                    Session["msgtype"] = null;
                    Session.Remove("msgtype");
                }
            }
            catch (Exception ex)
            {
            }
            //return output;
        }
        public ActionResult Create(BlockDataUserCreateModel model)
        {
            Logging.WriteToLog(this.GetType().ToString() + "-create()", LogType.Access);
            if (null == Session[this.SESSION_NAME_USERID])
            {
                return(RedirectToAction("Login", "Home"));
            }
            if (Session["IsAdmin"] == null || (bool)Session["IsAdmin"] == false)
            {
                return(RedirectToAction("Logout", "Home"));
            }
            ViewData["data_form"] = TempData["data"];
            // get language

            this.GetLanguage();

            // validate du lieu
            if (!string.IsNullOrEmpty(model.Email))
            {
                string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                                    @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                                    @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
                Regex re = new Regex(emailRegex);
                if (!re.IsMatch(model.Email))
                {
                    ModelState.AddModelError("Email", "Email is not valid");
                    Session["msg_code"] = -1;
                    Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.error_email");
                    TempData["data"]    = model;
                    return(RedirectToAction("Create"));
                }
            }
            if (model.Password != model.ConfirmPassword)
            {
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.error_password");
                TempData["data"]    = model;
                return(RedirectToAction("Create"));
            }

            if (!string.IsNullOrEmpty(model.Phone))
            {
                string phoneRegex = @"^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$";
                Regex  re         = new Regex(phoneRegex);
                if (!re.IsMatch(model.Phone))
                {
                    ModelState.AddModelError("Phone", "Phone is not valid");
                    Session["msg_code"] = -1;
                    Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.error_phone");
                    TempData["data"]    = model;
                    return(RedirectToAction("Create"));
                }
            }

            //if (model.LstSelectedRole.Count() == 0)
            //{
            //    ModelState.AddModelError("ListRoles", "Role is not valid");
            //    Session["msg_code"] = -1;
            //    Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.error_Role");
            //    TempData["data"] = model;
            //    return RedirectToAction("Create");
            //}



            //**************** DATABASE PROCESS*******************************************************
            this.SetConnectionDB();

            UserServices services = new UserServices(this.DBConnection);
            // check tài khoản đã tồn tại trong hệ thống hay chưa

            var             checkUser = services.GetList();
            EntityUserModel Usercheck = new EntityUserModel();

            if (model.IsSuperAdmin == true)
            {
                var User = checkUser.FirstOrDefault(x => x.UserName == model.UserName && x.UserId != model.UserId);
                Usercheck = User;
            }
            else
            {
                var CodeUser = services.GetCodeByDeptId(model.DeptId);
                var User     = checkUser.FirstOrDefault(x => x.UserName == model.UserName && x.UserId != model.UserId && (x.DeptId == model.DeptId || x.Code == CodeUser));
                Usercheck = User;
            }
            if (Usercheck != null)
            {
                Session["msg_code"] = -1;
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.error_User");
                TempData["data"]    = model;
                return(RedirectToAction("Create"));
            }

            int result = services.Create(model);

            if (services.ERROR != null)
            {
                FileHelper.SaveFile(new { data = model, ERROR = services.ERROR }, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + APIStringHelper.GenerateFileId() + ".txt");
            }
            //**************** GET LANGUAGE AND MESSAGE******************************************************************
            //this.GetLanguage();

            if (result > 0)
            {
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.success");
            }
            else
            {
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.error_business_1");
            }

            Session["msg_code"] = result;
            if (model.UserId > 0 && result > 1)
            {
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_user_create.success_edit");
            }
            //***********************INSERT OR EDIT SUCCESSFULLY * *************************************************
            if (result > 0)
            {
                return(RedirectToAction("List"));
            }
            TempData["data"] = model;
            //ViewBag.User = model;
            //this.SetCommonData();
            //BlockLangUserCreateModel blockLang = new BlockLangUserCreateModel();
            //BI_Project.Models.UI.BlockModel blockModel = new Models.UI.BlockModel("block_user_create", this.LANGUAGE_OBJECT, blockLang);
            //blockModel.DataModel = model;
            //ViewData["BlockData"] = blockModel;
            //ViewData["action_block"] = "Users/block_user_create";
            return(RedirectToAction("Create"));
            //return View("~/" + this.THEME_FOLDER + "/" + this.THEME_ACTIVE + "/index.cshtml");


            //*************************************************************************
            //BlockLangRoleCreateModel blockLang = new BlockLangRoleCreateModel();
            //BI_Project.Models.UI.BlockModel blockModel = new Models.UI.BlockModel("block_role_create", this.LANGUAGE_OBJECT, blockLang);
            //blockModel.DataModel = model;
            //ViewData["BlockData"] = blockModel;
            //return View("~/" + this.THEME_FOLDER + "/" + this.THEME_ACTIVE + "/index.cshtml");

            //return RedirectToAction("Create?roleid="+model.RoleId);
        }
        public ActionResult Create(EntityDepartmentModel model)
        {
            if (null == Session[this.SESSION_NAME_USERID])
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (Session["IsAdmin"] == null)
            {
                return(RedirectToAction("Logout", "Home"));
            }
            this.SetConnectionDB();

            this.GetLanguage();
            int output = 0;

            if (model.Code == null)
            {
                Session["msg_code"] = -1;
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_department_create.error_code");
                TempData["data"]    = model;
                return(RedirectToAction("Create"));
            }
            model.Code = model.Filter01.Substring(0, 2);
            DepartmentServices departServices = new DepartmentServices(this.DBConnection);

            output = departServices.CreateDepart(model);

            /****************************************RESPONSE FAILE OR SUCCESS******************************************/

            //this.GetLanguage();
            BlockDepartmentCreateLangModel blockLang = new BlockDepartmentCreateLangModel();

            blockLang.BlockName = "block_department_create";
            blockLang.SetLanguage(this.LANGUAGE_OBJECT);
            Session["msg_text"] = blockLang.GetMessage(output);
            Session["msg_code"] = output;

            if (departServices.ERROR != null)
            {
                BI_Project.Helpers.FileHelper.SaveFile(departServices.ERROR, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + BI_Project.Helpers.Utility.APIStringHelper.GenerateFileId() + ".txt");
            }

            if (model.DepartId > 0 && output > 0)
            {
                Session["msg_text"] = blockLang.GetLangByPath("messages.block_department_create.success_edit", this.LANGUAGE_OBJECT);
            }
            if (output == 0)
            {
                Session["msg_text"] = blockLang.GetLangByPath("messages.block_department_create.error_business_1", this.LANGUAGE_OBJECT);
                //return RedirectToAction("Create?roleid=" + model.RoleId);
            }
            if (output > 0)
            {
                return(RedirectToAction("List"));
            }


            TempData["data"] = model;
            return(RedirectToAction("Create"));
        }