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"; } }
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 { } }