Ejemplo n.º 1
0
        private void FrmLogin_Load(object sender, EventArgs e)
        {
            if (File.Exists("key.xml"))
            {
                string xml = File.ReadAllText("key.xml");
                myrsa.FromXmlString(xml);

                Microsoft.Win32.RegistryKey ReadKey;
                ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareAccount");

                string UserName = "";
                string Password = "";

                try      {
                    UserName = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("UserName").ToString());
                    Password = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("Password").ToString());
                }
                catch (Exception) { }

                bool SavePass = false;
                try   {
                    SavePass = bool.Parse(ReadKey.GetValue("SavePassword").ToString());
                }
                catch (Exception) { }

                bool ConnectOnline = true;
                try    {
                    //ConnectOnline =bool.Parse(ReadKey.GetValue("ConnectOnline").ToString());
                    ConnectOnline = true;
                }
                catch (Exception)   { }
                chkConnectOptions.Checked = ConnectOnline;

                if (SavePass == true)
                {
                    txtmatkhau.Text     = Password;
                    txttendangnhap.Text = UserName;
                    chkSaveInfo.Checked = true;
                }
                else
                {
                    txtmatkhau.Text     = "";
                    txttendangnhap.Text = "";
                    chkSaveInfo.Checked = false;
                }
            }
            else
            {
                File.WriteAllText("key.xml", myrsa.ToXmlString(true));
            }
        }
        private void frmUpdateSoftware_Load(object sender, EventArgs e)
        {
            Microsoft.Win32.RegistryKey ReadKey;
            ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareUpdate");

            bool AutoUpdate = false;

            try
            {
                AutoUpdate = bool.Parse(ReadKey.GetValue("AutoUpdate").ToString());
            }
            catch (Exception) { }

            if (AutoUpdate == true)
            {
                checkBoxAutoUpdate.Checked = true;
            }
            else
            {
                checkBoxAutoUpdate.Checked = false;
            }
        }
Ejemplo n.º 3
0
        public frmServerConfig()
        {
            InitializeComponent();
            try
            {
                Microsoft.Win32.RegistryKey ReadKey;
                ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareAccount", true);
                if (ReadKey != null)
                {
                    string ServerName       = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("ServerName").ToString());
                    string DatabaseUser     = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("DatabaseUser").ToString());
                    string DatabasePassword = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("DatabasePassword").ToString());
                    string DatabaseName     = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("DatabaseName").ToString());

                    txtDatabaseName.Text = DatabaseName;
                    txtDatabasePass.Text = DatabasePassword;
                    txtDatabaseUser.Text = DatabaseUser;
                    txtServerName.Text   = ServerName;
                }
            }
            catch (Exception)
            {}
        }
Ejemplo n.º 4
0
        private void bgAutoUpdate_DoWork(object sender, DoWorkEventArgs e)
        {
            TimeSpan interval = new TimeSpan(0, 0, 10);

            Thread.Sleep(interval);
            Microsoft.Win32.RegistryKey ReadKey;
            ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareUpdate");
            if (ReadKey == null)
            {
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("AutoCareUpdate");
                key.SetValue("AutoUpdate", true);
                key.Close();
            }

            bool AutoUpdate = false;

            try
            {
                AutoUpdate = bool.Parse(ReadKey.GetValue("AutoUpdate").ToString());
            }
            catch (Exception) { }

            if (AutoUpdate == true)
            {
                try
                {
                    DataTable dt = new DataTable();

                    using (SqlConnection cnn = Class.datatabase.getConnection())
                    {
                        cnn.Open();

                        SqlDataAdapter adap = new SqlDataAdapter(@"SELECT TOP 1 * FROM Software_Update ORDER BY SoftwareId DESC", cnn);

                        adap.Fill(dt);

                        if (dt.Rows.Count > 0)
                        {
                            if (dt.Rows[0][3].ToString() != oldversion)
                            {
                                frmMessUpdateSW frm = new frmMessUpdateSW();
                                frm.NameVersion    = dt.Rows[0][1].ToString();
                                frm.OldVerSion     = oldversion;
                                frm.NewVersion     = dt.Rows[0][3].ToString();
                                frm.ChangeLogs     = dt.Rows[0][4].ToString();
                                frm.UpdateLocation = dt.Rows[0][5].ToString();
                                frm.FileSize       = dt.Rows[0][6].ToString();
                                frm.md5            = dt.Rows[0][7].ToString();

                                Uri    location   = new Uri(dt.Rows[0][5].ToString());
                                string fileName   = dt.Rows[0][1].ToString();
                                string idsoftware = dt.Rows[0][0].ToString();
                                string NewVersion = dt.Rows[0][3].ToString();

                                if (frm.ShowDialog() == DialogResult.OK)
                                {
                                    frmUpdateDownload form   = new frmUpdateDownload(location, fileName, idsoftware, oldversion, NewVersion);
                                    DialogResult      result = form.ShowDialog();

                                    if (result == DialogResult.OK)
                                    {
                                        dt.Dispose();
                                    }
                                    else if (result == DialogResult.Abort)
                                    {
                                        MessageBox.Show("Tải về bản cập nhật đã bị hủy bỏ!\nChương trình chưa được cập nhật!", "Hủy bỏ tải về cập nhật", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        dt.Dispose();
                                    }
                                    else
                                    {
                                        MessageBox.Show(" Đã xảy ra vấn đề trong lúc tải về bản cập nhật!\nVui lòng thử lại sau!", "Lỗi tải về bản cập nhật", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        dt.Dispose();
                                    }
                                }
                            }
                        }
                        cnn.Close();
                    }
                }
                catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message + "\nVui lòng kiểm tra lại đường truyền mạng!"); }
            }
        }
Ejemplo n.º 5
0
        private void btndangnhap_Click(object sender, EventArgs e)
        {
            try            {
                if (chkConnectOptions.Checked == true)
                {
                    //dbconfig dbInfo = new dbconfig("HGUR7339823U43983RHDUHF72GMB938374HNGJDHEU", "MVNFH716188273646589GJFUJF83IU4JHT84IU5898RUT", "99845UU684UJRJTHYEIE83I4U584UIOIRUY84U54Y574I", txttendangnhap.Text.Trim(), txtmatkhau.Text.Trim());
                    //ConnectionDB dbConection = new ConnectionDB(dbInfo);
                    //Class.datatabase.connect = dbConection.GetConnection;
                    //if (dbConection.GetConnection == "")
                    //{
                    //    MessageBox.Show("Tài khoản hoặc mật khẩu không chính xác. Vui lòng kiểm tra lại");
                    //    return;
                    //}
                    //cn = dbConection.GetConnection;
                }
                else
                {
                    Microsoft.Win32.RegistryKey ReadKey;
                    ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareAccount", true);
                    if (ReadKey != null)
                    {
                        string ServerName       = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("ServerName").ToString());
                        string DatabaseUser     = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("DatabaseUser").ToString());
                        string DatabasePassword = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("DatabasePassword").ToString());
                        string DatabaseName     = AutoCareUtil.Utilities.Decode(ReadKey.GetValue("DatabaseName").ToString());

                        cn = "server=" + ServerName + ";uid=" + DatabaseUser + ";pwd=" + DatabasePassword + ";database=" + DatabaseName;
                        Class.datatabase.connect = cn;
                    }
                    //cn = Class.datatabase.connect;
                }
                connect();

                SqlCommand c = new SqlCommand("Select top 1 username,idcongty,idnhanvien,idcuahang,Pass, Quyen, TenNhanVien from NhanVien_TaiKhoanDangNhap where username=@username", con);
                c.Parameters.AddWithValue("@username", txttendangnhap.Text.Trim());
                da = new SqlDataAdapter(c);
                da.Fill(dttkdn);
                if (dttkdn.Rows.Count > 0)
                {
                    DataRow nhanvien = dttkdn.Rows[0];
                    Class.EmployeeInfo.idnhanvien  = Convert.ToInt32(nhanvien["idnhanvien"]);
                    Class.EmployeeInfo.IdCuaHang   = nhanvien["idcuahang"].ToString();
                    Class.EmployeeInfo.TenNhanVien = nhanvien["TenNhanVien"].ToString();
                    Class.EmployeeInfo.IdCongTy    = nhanvien["IdCongty"].ToString();
                    Class.EmployeeInfo.Pass        = nhanvien["Pass"].ToString();
                    Class.EmployeeInfo.Quyen       = nhanvien["Quyen"].ToString();
                    Class.EmployeeInfo.UserName    = nhanvien["username"].ToString();

                    string idconty = nhanvien["IdCongty"].ToString();

                    // lay thong tin cong ty
                    SqlCommand com = new SqlCommand("select * from Congty where idcongty = " + idconty, con);
                    da.SelectCommand = com;
                    da.Fill(tblcongty);
                    if (tblcongty.Rows.Count > 0)
                    {
                        Class.CompanyInfo.tencongty = tblcongty.Rows[0]["tencongty"].ToString();
                        Class.CompanyInfo.diachi    = tblcongty.Rows[0]["diachi"].ToString();
                        Class.CompanyInfo.phone     = tblcongty.Rows[0]["Dienthoai"].ToString();
                        idconty = tblcongty.Rows[0]["idCongty"].ToString();
                        Class.CompanyInfo.idcongty              = idconty;
                        Class.CompanyInfo.quota                 = tblcongty.Rows[0]["QuotaRemain"].ToString();
                        Class.CompanyInfo.secretkey             = tblcongty.Rows[0]["SecretKey"].ToString();
                        Class.CompanyInfo.sotiennhantinbaoduong = int.Parse(tblcongty.Rows[0]["SoTienNhanTinBaoDuong"].ToString());
                        Class.CompanyInfo.GoiPhanMem            = tblcongty.Rows[0]["GoiPhanMem"].ToString();
                    }
                    else
                    {
                        MessageBox.Show("Lỗi dữ liệu: Thông tin công ty của bạn chưa được cung cấp");
                        return;
                    }
                    try                    {
                        Class.CompanyInfo.cauhinhdotbaoduong = new SqlCommand("select ThangNhan from SMSMaintenanceConfig where idcongty=" + idconty, con).ExecuteScalar().ToString();
                    }
                    catch { }
                    // lay thong tin cua hang
                    string idscuahang = "";
                    using (SqlDataReader rd = new SqlCommand("select idcuahang from cuahang where idcongty=" + idconty, con).ExecuteReader())                    {
                        while (rd.Read())
                        {
                            idscuahang += rd[0].ToString() + ",";
                        }
                    }
                    if (idscuahang != "")
                    {
                        Class.CompanyInfo.IdsCuaHang = idscuahang.TrimEnd(',');
                    }

                    // kiem tra thuong hieu
                    object obj = new SqlCommand("select top 1 thuonghieu from ThuongHieu where idcongty=" + idconty, con).ExecuteScalar();
                    if (obj != null)
                    {
                        Class.CompanyInfo.sendername = obj != null?obj.ToString() : "";
                    }
                    else
                    {
                        MessageBox.Show("Lỗi Thương hiệu: Công ty bạn chưa được cấp thương hiệu");
                        return;
                    }
                    // kiem tra mat khau
                    string     pass = Class.Checksum.GetMd5Hash(txtmatkhau.Text, Class.CompanyInfo.secretkey);
                    SqlCommand cmd  = new SqlCommand("select * from Taikhoandangnhap where username=@username and pass=@pass", con);
                    cmd.Parameters.AddWithValue("@username", txttendangnhap.Text);
                    cmd.Parameters.AddWithValue("@pass", pass);
                    bool isPass = false;
                    using (SqlDataReader rd = cmd.ExecuteReader())                    {
                        while (rd.Read())
                        {
                            isPass = true;
                            if (chkSaveInfo.Checked)
                            {
                                //string strencrypt = txttendangnhap.Text + "|" + txtmatkhau.Text;
                                //byte[] strby = myrsa.Encrypt(Encoding.Unicode.GetBytes(strencrypt), false);
                                //File.WriteAllText("info.dat", Convert.ToBase64String(strby));

                                Microsoft.Win32.RegistryKey ReadKey;
                                ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareAccount", true);
                                if (ReadKey == null)
                                {
                                    Microsoft.Win32.RegistryKey key;
                                    key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("AutoCareAccount");
                                    key.SetValue("UserName", AutoCareUtil.Utilities.Encode(txttendangnhap.Text.Trim()));
                                    key.SetValue("Password", AutoCareUtil.Utilities.Encode(txtmatkhau.Text.Trim()));
                                    key.SetValue("SavePassword", true);
                                    key.SetValue("ConnectOnline", chkConnectOptions.Checked);
                                    key.Close();
                                }
                                else
                                {
                                    ReadKey.SetValue("UserName", AutoCareUtil.Utilities.Encode(txttendangnhap.Text.Trim()));
                                    ReadKey.SetValue("Password", AutoCareUtil.Utilities.Encode(txtmatkhau.Text.Trim()));
                                    ReadKey.SetValue("SavePassword", true);
                                    ReadKey.SetValue("ConnectOnline", chkConnectOptions.Checked);
                                    ReadKey.Close();
                                }
                            }
                            else
                            {
                                try      {
                                    Microsoft.Win32.RegistryKey ReadKey;
                                    ReadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("AutoCareAccount", true);
                                    ReadKey.SetValue("SavePassword", false);
                                }
                                catch (Exception)   { }
                            }

                            RibMain fmain = new RibMain();
                            fmain.Show();
                            this.Hide();
                        }
                    }
                    if (!isPass)
                    {
                        MessageBox.Show("Bạn đăng nhập không thành công!\n Hãy kiểm tra lại mật khẩu");
                    }
                }
                else
                {
                    MessageBox.Show("Bạn đăng nhập không thành công!\nHãy kiểm tra lại tài khoản đăng nhập.");
                    this.txttendangnhap.Focus();
                }
            }
            catch (Exception ex)  {
                MessageBox.Show("Bạn đăng nhập không thành công kiểm tra lại thông tin kết nối và đường truyền mạng.\n" + ex.Message);
            }
            finally    {
                con.Close();
            }
        }