Beispiel #1
0
        public ActionResult ChangePassword(string id = "", string oldPassword = "", string newPassword = "", string reType = "")
        {
            if (newPassword == reType && newPassword == oldPassword)
            {
                SetAlert("New password must not duplicate Old password", "warning");
            }

            else if (newPassword == reType)
            {
                if (UserAccountBLL.UpdatePassword(id, EncodeMD5.EncodeMD5B(oldPassword), EncodeMD5.EncodeMD5B(newPassword)))
                {
                    SetAlert("Change password success !", "success");
                }
                else
                {
                    SetAlert("Old password do not match !", "danger");
                }
            }

            else
            {
                SetAlert("Retype password do not match", "warning");
            }

            return(View());
        }
 private void Userconfig_Load(object sender, EventArgs e)
 {
     UserConfigPath = @"./Files/UserConfig.json";
     if (File.Exists(UserConfigPath))
     {
         userconfig            = JsonConvert.DeserializeObject <UserConfigModel>(File.ReadAllText(UserConfigPath));
         txtToMailAddress.Text = userconfig.ToMailAddress = EncodeMD5.DecryptString(userconfig.ToMailAddress, "ITFramasBDVN");
         txtCCMailAddress.Text = userconfig.CCMailAddress = EncodeMD5.DecryptString(userconfig.CCMailAddress, "ITFramasBDVN");
         txtMaterial.Text      = EncodeMD5.DecryptString(userconfig.Mixing_Material_BoxWeight.ToString(), "ITFramasBDVN");
         userconfig.Mixing_Material_BoxWeight = txtMaterial.Text;
         txtRecycle.Text = EncodeMD5.DecryptString(userconfig.Mixing_Recycle_BoxWeight.ToString(), "ITFramasBDVN");
         userconfig.Mixing_Recycle_BoxWeight = txtRecycle.Text;
         txtIncoming.Text = EncodeMD5.DecryptString(userconfig.Incoming_BoxWeight.ToString(), "ITFramasBDVN");
         userconfig.Incoming_BoxWeight = txtIncoming.Text;
         txtCrushing.Text = EncodeMD5.DecryptString(userconfig.Crushing_BoxWeight.ToString(), "ITFramasBDVN");
         userconfig.Crushing_BoxWeight = txtCrushing.Text;
     }
     else
     {
         userconfig            = new UserConfigModel();
         txtToMailAddress.Text = userconfig.ToMailAddress = "*****@*****.**";
         txtCCMailAddress.Text = userconfig.CCMailAddress = "*****@*****.**";
         txtMaterial.Text      = userconfig.Mixing_Material_BoxWeight = "0.16";
         txtRecycle.Text       = userconfig.Mixing_Recycle_BoxWeight = "1.14";
         txtIncoming.Text      = userconfig.Incoming_BoxWeight = "2.1966";
         txtCrushing.Text      = userconfig.Crushing_BoxWeight = "1.14";
     }
 }
        public ActionResult ResetPassword(string email = "", string newPassword = "", string confirmPassword = "")
        {
            if (newPassword != confirmPassword)
            {
                ModelState.AddModelError("newPass", "Mật khẩu mới và nhập lại mật khẩu không khớp");
            }
            if (!ModelState.IsValid)
            {
                ViewBag.email       = email;
                ViewBag.newPass     = newPassword;
                ViewBag.confirmPass = confirmPassword;
                return(View());
            }
            var reset = AccountBLL.Change_Pass(email, EncodeMD5.GetMD5(newPassword));

            if (reset)
            {
                return(RedirectToAction("Login"));
            }
            else
            {
                ViewBag.email       = email;
                ViewBag.newPass     = newPassword;
                ViewBag.confirmPass = confirmPassword;
                return(View());
            }
        }
Beispiel #4
0
        private void SaveScaleConfig()
        {
            scaleConfig.ScaleIP   = EncodeMD5.EncryptString(txtScaleIP.Text, "ITFramasBDVN");
            scaleConfig.ScalePort = EncodeMD5.EncryptString(txtScalePort.Text, "ITFramasBDVN");
            string json = JsonConvert.SerializeObject(scaleConfig, Formatting.Indented);

            File.WriteAllText(pathScaleConfig, json);
        }
Beispiel #5
0
        //private void GetComPort()
        //{
        //    string[] portNames = SerialPort.GetPortNames();     //<-- Reads all available comPorts
        //    foreach (var portName in portNames)
        //    {
        //        cbbComPort.Properties.Items.Add(portName);                  //<-- Adds Ports to combobox
        //    }
        //    cbbComPort.SelectedIndex = 0;
        //}


        private void SaveMailConfig()
        {
            mailConfig.FromMailAddress = EncodeMD5.EncryptString(txtFromMailAddress.Text, "ITFramasBDVN");
            mailConfig.Password        = EncodeMD5.EncryptString(txtMailPassword.Text, "ITFramasBDVN");
            mailConfig.Host            = EncodeMD5.EncryptString(txtHost.Text, "ITFramasBDVN");
            mailConfig.Port            = EncodeMD5.EncryptString(txtPort.Text, "ITFramasBDVN");
            string json = JsonConvert.SerializeObject(mailConfig, Formatting.Indented);

            File.WriteAllText(pathMailserverConfig, json);
        }
Beispiel #6
0
        //lưu thông tin server vào lại settings
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                serverName = txtServerName.Text.Trim();
                dbName     = txtDbName.Text.Trim();
                userName   = txtUserName.Text;
                password   = txtPassword.Text;

                DataProvider.Instance.connectionStr = $"Data Source={serverName}" +
                                                      $";Database={dbName};UID={userName}" +
                                                      $";Password={password}; Min Pool Size=0;Max Pool Size=1000;Pooling=true; Connect Timeout=100;";


                //cai đặt thông tin xong thì kiểm tra kết nối đến DB server, OK thì vào form Login
                //lỗi thì nằm yên tại chỗ
                SplashScreenManager.ShowForm(this, typeof(frmProcessing), true, true, false);
                SplashScreenManager.Default.SetWaitFormCaption("Check database server...");
                var checkConnectDB = DataProvider.Instance.ExecuteScalar("select count(*) from tblAccount"); //kiểm tra kết nối đến DB server
                Thread.Sleep(1000);                                                                          //thời gian chờ cho tiến trình chạy
                if (checkConnectDB != null && (int)checkConnectDB > 0)                                       //kết nối thành công
                {
                    SplashScreenManager.Default.SetWaitFormCaption("Connect databases successful...");
                    Thread.Sleep(1000);
                    SplashScreenManager.CloseForm();

                    //lưu lại trạng thái cấu hình là đã cấu hình rồi vào settings
                    //mã hóa MD5 rồi mới lưu xuống textFile
                    configFirstInstall = "True";
                    WriteFile(pathApp, $"serverName:{EncodeMD5.EncryptString(serverName, "ITFramasBDVN")}|dbName:{EncodeMD5.EncryptString(dbName, "ITFramasBDVN")}" +
                              $"|userName:{EncodeMD5.EncryptString(userName, "ITFramasBDVN")}|password:{EncodeMD5.EncryptString(password, "ITFramasBDVN")}|configFirstInstall:{configFirstInstall}");
                    //Save Mail Config
                    SaveMailConfig();
                    //Save Scale Config
                    SaveScaleConfig();
                    //vao form Login
                    frmLogin newForm = new frmLogin();
                    this.Hide();
                    newForm.ShowDialog();
                    this.Close();
                }
                else//kết nối thất bại
                {
                    SplashScreenManager.Default.SetWaitFormCaption("Connect databases fail...");
                    Thread.Sleep(1000);
                    SplashScreenManager.CloseForm();
                }
            }
            catch
            {
            }
        }
        public ActionResult Login(string email = "", string password = "")
        {
            if (Request.HttpMethod == "GET")
            {
                return(View());
            }
            else
            {
                //TODO: Kiểm tra thông tin đăng nhập qua CSDL
                var userAccount = AccountBLL.Authorize(email, EncodeMD5.GetMD5(password), UserAccountTypes.Employee);
                if (userAccount != null)
                {
                    WebUserData cookiesData = new Admin.WebUserData()
                    {
                        UserID    = userAccount.UserID,
                        FullName  = userAccount.FullName,
                        GroupName = userAccount.GroupName,
                        LoginTime = DateTime.Now,
                        SessionID = Session.SessionID,
                        ClientIP  = Request.UserHostAddress,
                        Photo     = userAccount.Photo,
                    };
                    FormsAuthentication.SetAuthCookie(cookiesData.ToCookieString(), false);
                    return(RedirectToAction("Index", "Dashboard"));
                }
                else
                {
                    ModelState.AddModelError("LoginError", "Đăng nhập thất bại");
                    ViewBag.Email = email;
                    return(View());
                }

                /*bool result = AccountBLL.Login(email, password);
                 * if (result)
                 * {
                 *  FormsAuthentication.SetAuthCookie(email, false);
                 *  return RedirectToAction("Index", "Dashboard");
                 * }
                 * else
                 * {
                 *  ModelState.AddModelError("LoginError", "Đăng nhập thất bại");
                 *  ViewBag.Email = email;
                 *  return View();
                 * }*/
            }
        }
 private bool SaveUserConfigConfig()
 {
     try
     {
         userconfig.ToMailAddress             = EncodeMD5.EncryptString(txtToMailAddress.Text, "ITFramasBDVN");
         userconfig.CCMailAddress             = EncodeMD5.EncryptString(txtCCMailAddress.Text, "ITFramasBDVN");
         userconfig.Mixing_Material_BoxWeight = EncodeMD5.EncryptString(txtMaterial.Text, "ITFramasBDVN");
         userconfig.Mixing_Recycle_BoxWeight  = EncodeMD5.EncryptString(txtRecycle.Text, "ITFramasBDVN");
         userconfig.Incoming_BoxWeight        = EncodeMD5.EncryptString(txtIncoming.Text, "ITFramasBDVN");
         userconfig.Crushing_BoxWeight        = EncodeMD5.EncryptString(txtCrushing.Text, "ITFramasBDVN");
         string json = JsonConvert.SerializeObject(userconfig, Formatting.Indented);
         File.WriteAllText(UserConfigPath, json);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 /// <summary>
 /// Trang thay đổi mật khẩu
 /// </summary>
 /// <returns></returns>
 public ActionResult ChangePassword(string email, string currentpassword, string password, string confirmpassword)
 {
     if (Request.HttpMethod == "GET")
     {
         return(View());
     }
     else
     {
         Employee employee = AccountBLL.GetPass(email);
         if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirmpassword))
         {
             ModelState.AddModelError("errorNull", "Mật khẩu không được để trống");
             return(View());
         }
         //if (currentpassword.Equals(employee.Password))
         if (String.Equals(employee.Password, EncodeMD5.GetMD5(currentpassword)))
         {
             if (password.Equals(confirmpassword))
             {
                 bool result = AccountBLL.Update(EncodeMD5.GetMD5(password), email);
                 if (result)
                 {
                     return(RedirectToAction("Index", "Dashboard"));
                 }
                 else
                 {
                     return(View());
                 }
             }
             else
             {
                 ModelState.AddModelError("errorCurrentpass", "Mật khẩu nhập lại không trùng khớp");
                 return(View());
             }
         }
         else
         {
             ModelState.AddModelError("errorOlderpass", "Mật khẩu cũ không đúng");
             return(View());
         }
     }
 }
        public ActionResult Login(string email = "", string password = "")
        {
            if (Request.HttpMethod == "GET")
            {
                return(View());
            }
            else
            {
                //bool result = AccountBLL.Login(email, EncodeMD5.GetMD5(password));
                var userAccount = AccountBLL.Athorize(email, EncodeMD5.GetMD5(password), UserAccountTypes.Employee);

                if (userAccount != null)
                {
                    WebUserData cookieData = new Admin.WebUserData()
                    {
                        UserID    = userAccount.UserID,
                        FullName  = userAccount.FullName,
                        GroupName = userAccount.Role,
                        LoginTime = DateTime.Now,
                        SessionID = Session.SessionID,
                        ClientIP  = Request.UserHostAddress,
                        Photo     = userAccount.Photo
                    };
                    FormsAuthentication.SetAuthCookie(cookieData.ToCookieString(), false);
                    return(RedirectToAction("Index", "Dashboard"));
                }
                else
                {
                    ModelState.AddModelError("login_error", "Đăng nhập thất bại");
                    ViewBag.Email    = email;
                    ViewBag.Password = password;
                    //ViewBag : Trao đổi dữ liệu
                    return(View());
                }
            }
        }
Beispiel #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //string _pass = Encryptor.MD5Hash(password);//1 cach ma hoa MD5 ko có pass
            string _pass = EncodeMD5.EncryptString(txtOldPassword.Text, "ITFramasBDVN");//mã hóa MD5 có pass

            if (oldPass == _pass)
            {
                if (EncodeMD5.EncryptString(txtNewPassword.Text, "ITFramasBDVN") == EncodeMD5.EncryptString(txtReNewPass.Text, "ITFramasBDVN"))
                {
                    if (DbAccount.Instance.UpdateAccountUser(GlobalVariable.userId.ToString(), txtUserName.Text, EncodeMD5.EncryptString(txtNewPassword.Text, "ITFramasBDVN")) > 0)
                    {
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show($"Fail! New passwords do not match.");
                }
            }
            else
            {
                MessageBox.Show($"Fail! Old password wrong!");
            }
        }
Beispiel #12
0
 public ActionResult ChangePwd(string email, string oldpass, string newpass, string repeatpass)
 {
     if (!UserAccountBLL.Check_Pass(email, EncodeMD5.GetMD5(oldpass)))
     {
         ModelState.AddModelError("errorPass", "Sai mật khẩu");
     }
     if (String.Equals(EncodeMD5.GetMD5(newpass), EncodeMD5.GetMD5(repeatpass)) == false)
     {
         ModelState.AddModelError("newPass", "Mật khẩu mới và nhập lại mật khẩu không khớp");
     }
     if (!ModelState.IsValid)
     {
         ViewBag.oldPass    = oldpass;
         ViewBag.newPass    = newpass;
         ViewBag.repeatPass = repeatpass;
         return(View());
     }
     else
     {
         bool rs = UserAccountBLL.Change_Pass(email, EncodeMD5.GetMD5(newpass));
         return(RedirectToAction("Index", "Dashboard"));
     }
     //return Content("OK");
 }
Beispiel #13
0
        public ActionResult Input(Employee data, HttpPostedFileBase files = null)
        {
            if (data.Country == "null")
            {
                ModelState.AddModelError("errorAddr", "Vui lòng chọn quốc gia");
            }
            if (data.Notes == null)
            {
                data.Notes = "";
            }
            if (data.Address == null)
            {
                data.Address = "";
            }
            if (data.HomePhone == null)
            {
                data.HomePhone = "";
            }
            if (data.City == null)
            {
                data.City = "";
            }
            if (data.PhotoPath == null)
            {
                data.PhotoPath = "";
            }
            if (!ModelState.IsValid)
            {
                return(View(data));
            }
            if (string.IsNullOrEmpty(data.FirstName))
            {
                ModelState.AddModelError("ErrorFirstName", "First name is required");
            }
            if (string.IsNullOrEmpty(data.LastName))
            {
                ModelState.AddModelError("ErrorLastName", "Last Name is required");
            }
            if (string.IsNullOrEmpty(data.Password))
            {
                ModelState.AddModelError("ErrorPassword", "Password is required");
            }

            /*if (string.IsNullOrEmpty(data.Email))
             * {
             *  data.Email = "";
             * }
             * if (string.IsNullOrEmpty(data.Address))
             * {
             *  data.Address = "";
             * }
             * if (string.IsNullOrEmpty(data.Notes))
             * {
             *  data.Notes = "";
             * }
             * if (string.IsNullOrEmpty(data.HomePhone))
             * {
             *  data.HomePhone = "";
             * }*/
            if (files != null)
            {
                string get           = DateTime.Now.ToString("ddMMyyyhhmmss");
                string fileExtension = Path.GetExtension(files.FileName);
                string fileName      = get + fileExtension;
                string path          = Path.Combine(Server.MapPath("~/Images"), fileName);
                data.PhotoPath = fileName;
                files.SaveAs(path);
            }
            if (!EncodeMD5.IsMD5(data.Password))
            {
                data.Password = EncodeMD5.GetMD5(data.Password);
            }
            if (data.EmployeeID == 0)
            {
                bool IsEmailExist = AccountBLL.IsEmailExist(data.Email, data.EmployeeID);
                if (IsEmailExist)
                {
                    ModelState.AddModelError("errorEmailDuplicate", "Email đã tồn tại. Vui lòng nhập email khác!");
                    return(View(data));
                }
                else
                {
                    int employeeID = HumanResourceBLL.Employee_Add(data);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                bool IsEmailExist = AccountBLL.IsEmailExist(data.Email, data.EmployeeID);
                if (IsEmailExist)
                {
                    ModelState.AddModelError("errorEmailDuplicate", "Email đã tồn tại. Vui lòng nhập email khác!");
                    return(View(data));
                }
                else
                {
                    bool updateResult = HumanResourceBLL.Employee_Update(data);
                }
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Input(Employee model, HttpPostedFileBase file = null, string oldEmail = "")
        {
            //try
            //{
            //    //Kiểm tra tính hợp lệ
            if (model.Notes == null)
            {
                model.Notes = "";
            }
            if (String.IsNullOrEmpty(model.Country))
            {
                ModelState.AddModelError("errorAddr", "Vui lòng chọn quốc gia");
            }
            if (String.IsNullOrEmpty(model.GroupName))
            {
                ModelState.AddModelError("errorRole", "Vui lòng chọn quyền");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var    listRoles = model.GroupName.Split(',');
            string groupName = "";

            foreach (var item in SelectListHelper.listRoles(false))
            {
                foreach (var role in listRoles)
                {
                    if (item.Value == role)
                    {
                        groupName += role + ",";
                    }
                }
            }
            model.GroupName = groupName.Remove(groupName.LastIndexOf(','));
            if (file != null)
            {
                string get           = DateTime.Now.ToString("ddMMyyyhhmmss");
                string fileExtension = Path.GetExtension(file.FileName);
                string fileName      = get + fileExtension;
                string path          = Path.Combine(Server.MapPath("~/Images"), fileName);
                model.PhotoPath = fileName;
                file.SaveAs(path);
            }
            if (!EncodeMD5.IsMD5(model.Password))
            {
                model.Password = EncodeMD5.GetMD5(model.Password);
            }
            if (model.EmployeeID == 0)
            {
                if (file == null)
                {
                    TempData["emptyFile"] = "Vui lòng chọn file";
                    return(View(model));
                }
                else if (HumanResourceBLL.Check_Email(model.Email))
                {
                    TempData["emptyEmail"] = "Email đã tồn tại";
                    return(View(model));
                }
                else
                {
                    int employeeID = HumanResourceBLL.Employee_Add(model);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                if (HumanResourceBLL.Check_Email(model.Email) && (oldEmail != model.Email))
                {
                    TempData["emptyEmail"] = "Email đã tồn tại";
                    ViewBag.oldEmail       = oldEmail;
                    return(View(model));
                }
                var getEmployee = HumanResourceBLL.Employee_Get(model.EmployeeID);
                if (file == null)
                {
                    model.PhotoPath = getEmployee.PhotoPath;
                }

                bool updateResult = HumanResourceBLL.Employee_Update(model);
                return(RedirectToAction("Index"));
            }

            //}
            //catch (Exception e)
            //{
            //    ModelState.AddModelError("", e.Message + ":" + e.StackTrace);
            //    return View(model);
            //}
        }
Beispiel #15
0
 //reset ve pass mac dinh "11111"
 private void btnReset_Click(object sender, EventArgs e)
 {
     if (lookUpUserName.Text != "[EditValue is null]" && !string.IsNullOrEmpty(lookUpUserName.Text))
     {
         if (DbAccount.Instance.UpdateAccountUser(lookUpUserName.EditValue.ToString(), lookUpUserName.Text, EncodeMD5.EncryptString("11111", "ITFramasBDVN")) > 0)
         {
             XtraMessageBox.Show($"Reset password successfull.");
         }
         else
         {
             XtraMessageBox.Show($"Fail, please try again!");
         }
     }
     else
     {
         XtraMessageBox.Show($"Fail, please try again!");
     }
 }
Beispiel #16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (dxValidationProvider1.Validate())
            {
                if (!string.IsNullOrEmpty(txtFullName.Text) && !string.IsNullOrEmpty(txtUserName.Text))
                {
                    int Count = Convert.ToInt32(DbAccount.Instance.OperatorRoleCheck(txtUserName.Text, "2").Rows[0][0]);
                    if (Count > 0)
                    {
                        XtraMessageBox.Show("User is exists!");
                    }
                    else
                    {
                        if (DbAccount.Instance.InsertAccount(txtUserName.Text, txtFullName.Text, EncodeMD5.EncryptString("11111", "ITFramasBDVN"), "2") > 0)
                        {
                            int    _id      = DbAccount.Instance.GetMaxIdAccount();
                            string order    = $"{checkEditImportOrder.Checked}|{checkEditPrintOrder.Checked}|{checkEditScaleOrder.Checked}";
                            string mixing   = $"{checkEditImportMixing.Checked}|{checkEditPrintMixing.Checked}|{checkEditScaleMixing.Checked}";
                            string incoming = $"{checkEditImportIncoming.Checked}|{checkEditPrintIncoming.Checked}|{checkEditScaleIncoming.Checked}";
                            string crush    = $"{checkEditImportCrush.Checked}|{checkEditPrintCrush.Checked}|{checkEditScaleCrush.Checked}";
                            DbAccount.Instance.InsertOperatorRole(_id.ToString(), order, mixing, incoming, crush);

                            //refresh laij danh sach user
                            DataTable _data = DbAccount.Instance.GetUserReset();
                            lookUpUserName.Properties.DataSource = _data;

                            XtraMessageBox.Show($"Successfull.");
                        }
                    }
                }
                else
                {
                    XtraMessageBox.Show($"Fail, please try again!");
                }
            }
        }
Beispiel #17
0
        private void frmConfigFirstInstall_Load(object sender, EventArgs e)
        {
            //try
            {
                // GetComPort();
                #region đọc textFile để lấy thông số cấu hình
                pathApp = $"{ Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\Files\\DbServerParametter.txt";//get path
                // Debug.WriteLine(pathApp);

                dataArr = ReadFile(pathApp).Split('|');

                //giải mã MD5 các thồng số với pass giải mã là "ITFramasBDVN"
                serverName = txtServerName.Text = EncodeMD5.DecryptString(dataArr[0].Split(':')[1], "ITFramasBDVN");
                dbName     = txtDbName.Text = EncodeMD5.DecryptString(dataArr[1].Split(':')[1], "ITFramasBDVN");
                userName   = txtUserName.Text = EncodeMD5.DecryptString(dataArr[2].Split(':')[1], "ITFramasBDVN");
                password   = txtPassword.Text = EncodeMD5.DecryptString(dataArr[3].Split(':')[1], "ITFramasBDVN");

                configFirstInstall = dataArr[4].Split(':')[1];//kiểm tra biến này nếu =False là cài đặt đầu tiên, =True là đã cài đặt rồi cho vào thẳng form Login
                #endregion

                //gắn connection
                DataProvider.Instance.connectionStr = $"Data Source={serverName}" +
                                                      $";Database={dbName};UID={userName}" +
                                                      $";Password={password}; Min Pool Size=0;Max Pool Size=1000;Pooling=true; Connect Timeout=100;";

                txtDbName.Enabled     = false;
                txtServerName.Enabled = false;
                txtUserName.Enabled   = false;
                txtPassword.Enabled   = false;
                btnSend.Enabled       = false;
                //Cấu hình Mail server
                pathMailserverConfig = @"./Files/MailserverConfig.json";
                if (File.Exists(pathMailserverConfig))
                {
                    mailConfig = JsonConvert.DeserializeObject <MailConfig>(File.ReadAllText(pathMailserverConfig));
                    txtFromMailAddress.Text = mailConfig.FromMailAddress = EncodeMD5.DecryptString(mailConfig.FromMailAddress, "ITFramasBDVN");
                    txtMailPassword.Text    = mailConfig.Password = EncodeMD5.DecryptString(mailConfig.Password, "ITFramasBDVN");
                    txtHost.Text            = mailConfig.Host = EncodeMD5.DecryptString(mailConfig.Host, "ITFramasBDVN");
                    txtPort.Text            = mailConfig.Port = EncodeMD5.DecryptString(mailConfig.Port, "ITFramasBDVN");
                }
                else
                {
                    mailConfig = new MailConfig();
                    mailConfig.FromMailAddress = txtFromMailAddress.Text = "*****@*****.**";
                    mailConfig.Password        = txtMailPassword.Text = "san48Ngu#";
                    mailConfig.Host            = txtHost.Text = "smtp.office365.com";
                    mailConfig.Port            = txtPort.Text = "587";
                }

                //Cấu hình Scale IP
                pathScaleConfig = @"./Files/ScaleConfig.json";
                if (File.Exists(pathScaleConfig))
                {
                    scaleConfig       = JsonConvert.DeserializeObject <ScaleConfig>(File.ReadAllText(pathScaleConfig));
                    txtScaleIP.Text   = scaleConfig.ScaleIP = EncodeMD5.DecryptString(scaleConfig.ScaleIP, "ITFramasBDVN");
                    txtScalePort.Text = scaleConfig.ScalePort = EncodeMD5.DecryptString(scaleConfig.ScalePort, "ITFramasBDVN");
                }
                else
                {
                    scaleConfig           = new ScaleConfig();
                    scaleConfig.ScaleIP   = txtScaleIP.Text = "192.168.1.236";
                    scaleConfig.ScalePort = txtScalePort.Text = "23";
                }
                //Đọc cấu hình của User
                pathUserConfig = @"./Files/UserConfig.json";
                if (File.Exists(pathUserConfig))
                {
                    userConfig = JsonConvert.DeserializeObject <UserConfigModel>(File.ReadAllText(pathUserConfig));
                }
                //khi cài chương trình chạy dầu tiên thì vào cấu hình DB server
                if (configFirstInstall == "True")
                {
                    txtDbName.Enabled     = true;
                    txtServerName.Enabled = true;
                    txtUserName.Enabled   = true;
                    txtPassword.Enabled   = true;
                    btnSend.Enabled       = true;
                }
                else//
                {
                    //Đẩy dữ liệu vào biến toàn cục

                    GlobalVariable.fromEmailAddress = txtFromMailAddress.Text;
                    GlobalVariable.fromEmailPass    = txtPassword.Text;
                    GlobalVariable.emailHost        = txtHost.Text;
                    GlobalVariable.emailPort        = txtPort.Text;

                    if (userConfig != null)
                    {
                        GlobalVariable.toEmailAddress          = EncodeMD5.DecryptString(userConfig.ToMailAddress, "ITFramasBDVN");
                        GlobalVariable.ccEmailAddress          = EncodeMD5.DecryptString(userConfig.CCMailAddress, "ITFramasBDVN");
                        GlobalVariable.boxWeightMixingMaterial = Convert.ToDouble(EncodeMD5.DecryptString(userConfig.Mixing_Material_BoxWeight, "ITFramasBDVN"));
                        GlobalVariable.boxWeightMixingRecycle  = Convert.ToDouble(EncodeMD5.DecryptString(userConfig.Mixing_Recycle_BoxWeight, "ITFramasBDVN"));
                        GlobalVariable.boxWeightIncoming       = Convert.ToDouble(EncodeMD5.DecryptString(userConfig.Incoming_BoxWeight, "ITFramasBDVN"));
                        GlobalVariable.boxWeightCrushing       = Convert.ToDouble(EncodeMD5.DecryptString(userConfig.Crushing_BoxWeight, "ITFramasBDVN"));
                    }

                    GlobalVariable.ipScale   = txtScaleIP.Text;
                    GlobalVariable.portScale = txtScalePort.Text;

                    SplashScreenManager.ShowForm(this, typeof(frmProcessing), true, true, false);
                    SplashScreenManager.Default.SetWaitFormCaption("Check database server...");
                    var checkConnectDB = DataProvider.Instance.ExecuteScalar("select count(*) from tblAccount"); //kiểm tra kết nối đến DB server
                    Thread.Sleep(1000);                                                                          //thời gian chờ cho tiến trình chạy
                    if (checkConnectDB != null && (int)checkConnectDB > 0)                                       //kết nối thành công
                    {
                        SplashScreenManager.Default.SetWaitFormCaption("Connect databases successful...");
                        Thread.Sleep(1000);
                        SplashScreenManager.CloseForm();

                        //vao form Login
                        frmLogin newForm = new frmLogin();
                        this.Hide();
                        newForm.ShowDialog();
                        this.Close();
                    }
                    else//kết nối thất bại
                    {
                        SplashScreenManager.Default.SetWaitFormCaption("Connect databases fail...");
                        Thread.Sleep(1000);
                        SplashScreenManager.CloseForm();
                    }
                }
            }
            //catch { }
        }
Beispiel #18
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public ActionResult Index()
 {
     ViewBag.num = EncodeMD5.IsMD5("11111111111111111111111111111111");
     return(View());
 }