Example #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var userName = this.txtUserName.Text.Trim();
            var password = this.txtPassword.Text.Trim();
            var email    = this.txtEmail.Text.Trim();
            var mobile   = this.txtMobile.Text.Trim();
            var fullName = this.txtFullName.Text.Trim();
            var role     = this.cboRole.SelectedValue;

            if (!validateUser())
            {
                return;
            }

            try
            {
                SQLiteCommon.BeginTran();
                string sql = "INSERT INTO M_USERS (USERID, PASSWORD, FULLNAME, EMAIL, MOBILE, ROLE, CREATEBY) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', {5}, '{6}')";
                sql = string.Format(sql, userName, password, fullName, email, mobile, role, CURRENT_USER);
                SQLiteCommon.ExecuteSqlNonResult(sql);
                SQLiteCommon.CommitTran();
                ShowMsg(MessageBoxIcon.Information, ADD_USER_SUCCESS);
                this.isSuccess    = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, ADD_USER_FAIL + " : " + ex.Message);
            }
        }
Example #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!validateCustomer())
            {
                return;
            }

            var companyName    = this.txtCompanyName.Text.Trim();
            var companyAddress = this.txtCompanyAddress.Text.Trim();
            var companyMobile  = this.txtCompanyMobile.Text.Trim();
            var cusName        = this.txtCusName.Text.Trim();
            var cusEmail       = this.txtCusEmail.Text.Trim();
            var cusMobile      = this.txtCompanyMobile.Text.Trim();

            SQLiteCommon.BeginTran();

            try
            {
                string sql = "UPDATE M_CUSTOMERS SET COMPANYNAME = '{0}', COMPANYADDRESS = '{1}', COMPANYMOBILE = '{2}', CUSNAME = '{3}' , CUSEMAIL = '{4}' , CUSMOBILE = '{5}', USERID = '{6}' WHERE ID = {7}";
                sql = string.Format(sql, companyName, companyAddress, companyMobile, cusName, cusEmail, cusMobile, CURRENT_USER, paramUpdate.ID);
                SQLiteCommon.ExecuteSqlNonResult(sql);

                SQLiteCommon.CommitTran();
                ShowMsg(MessageBoxIcon.Information, UPDATE_CUSTOMER_SUCCESS);
                this.isSuccess    = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, UPDATE_CUSTOMER_FAIL + " : " + ex.Message);
            }
        }
Example #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!validateCustomer())
            {
                return;
            }

            var companyName    = this.txtCompanyName.Text.Trim();
            var companyAddress = this.txtCompanyAddress.Text.Trim();
            var companyMobile  = this.txtCompanyMobile.Text.Trim();
            var cusName        = this.txtCusName.Text.Trim();
            var cusEmail       = this.txtCusEmail.Text.Trim();
            var cusMobile      = this.txtCompanyMobile.Text.Trim();

            try
            {
                SQLiteCommon.BeginTran();
                string sql = "INSERT INTO M_CUSTOMERS (COMPANYNAME, COMPANYADDRESS, COMPANYMOBILE, CUSNAME, CUSEMAIL, CUSMOBILE, USERID) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')";
                sql = string.Format(sql, companyName, companyAddress, companyMobile, cusName, cusEmail, cusMobile, CURRENT_USER);
                SQLiteCommon.ExecuteSqlNonResult(sql);
                SQLiteCommon.CommitTran();
                ShowMsg(MessageBoxIcon.Information, ADD_CUSTOMER_SUCCESS);
                this.btnAdd.Enabled = false;
                this.isSuccess      = true;
                this.DialogResult   = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, ADD_CUSTOMER_FAIL + " : " + ex.Message);
            }
        }
Example #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var deviceName = this.txtDeviceName.Text.Trim();
            var macAddress = this.txtMacAddress.Text.Trim();

            if (!validateDevice())
            {
                return;
            }

            try
            {
                SQLiteCommon.BeginTran();
                string sql = "INSERT INTO M_DEVICES (DEVICENAME, MACADDRESS, USERID) VALUES ('{0}', '{1}', '{2}')";
                sql = string.Format(sql, deviceName, macAddress, CURRENT_USER);
                SQLiteCommon.ExecuteSqlNonResult(sql);
                SQLiteCommon.CommitTran();
                ShowMsg(MessageBoxIcon.Information, ADD_DEVICE_SUCCESS);
                this.isSuccess    = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, ADD_DEVICE_FAIL + " : " + ex.Message);
            }
        }
Example #5
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!validateDevice(false))
            {
                return;
            }

            var deviceName = this.txtDeviceName.Text.Trim();
            var macAddress = this.txtMacAddress.Text.Trim();

            SQLiteCommon.BeginTran();

            try
            {
                string sql = "UPDATE M_DEVICES SET DEVICENAME = '{0}', MACADDRESS = '{1}' WHERE ID = {2}";
                sql = string.Format(sql, deviceName, macAddress, paramUpdate.ID);
                SQLiteCommon.ExecuteSqlNonResult(sql);

                SQLiteCommon.CommitTran();
                ShowMsg(MessageBoxIcon.Information, UPDATE_DEVICE_SUCCESS);
                this.isSuccess    = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, UPDATE_DEVICE_FAIL + " : " + ex.Message);
            }
        }
Example #6
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!validateUser(false))
            {
                return;
            }

            var userName = this.txtUserName.Text.Trim();
            var password = this.txtPassword.Text.Trim();
            var email    = this.txtEmail.Text.Trim();
            var mobile   = this.txtMobile.Text.Trim();
            var fullName = this.txtFullName.Text.Trim();
            var role     = this.cboRole.SelectedValue ?? 1;

            SQLiteCommon.BeginTran();

            try
            {
                string sql = "UPDATE M_USERS SET PASSWORD = '******', FULLNAME = '{1}', EMAIL = '{2}', MOBILE = '{3}' , ROLE = {4} WHERE USERID = '{5}'";
                sql = string.Format(sql, password, fullName, email, mobile, role, paramUpdate.UserId);
                SQLiteCommon.ExecuteSqlNonResult(sql);

                SQLiteCommon.CommitTran();
                ShowMsg(MessageBoxIcon.Information, UPDATE_USER_SUCCESS);
                this.isSuccess    = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, UPDATE_USER_FAIL + " : " + ex.Message);
            }
        }
Example #7
0
        private void dgvCusKeys_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }

            var cusSelected = (MCustomer)dgvCustomerList.CurrentRow.DataBoundItem;

            CreateKeyForm createKeyForm = new CreateKeyForm();

            createKeyForm.Mode            = CreateKeyForm.ViewMode.EDIT;
            createKeyForm.currentCustomer = cusSelected;
            CustomerKey   cusKey    = null;
            List <string> lstOldMac = new List <string>();

            try
            {
                var x = SQLiteCommon.GetALlKeyDevices();

                cusKey = (CustomerKey)dgvCusKeys.CurrentRow.DataBoundItem;
                if (cusKey == null)
                {
                    return;
                }

                lstOldMac = SQLiteCommon.GetCustomerKeyByKeyCode(cusKey.KeyCode).ListMacAddress;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, ex.Message);
            }

            Params param = new Params
            {
                KeyCode     = cusKey.KeyCode,
                MachineCode = cusKey.MachineCode,
                ListMacs    = lstOldMac
            };

            createKeyForm.param = param;
            createKeyForm.InitForm();
            DialogResult result = createKeyForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (createKeyForm.isSuccess)
                {
                    loadCustomerKey();
                }
            }
        }
Example #8
0
 private void loadDevices()
 {
     try
     {
         List <MDevice> lstDevice = SQLiteCommon.GetALlDevices();
         BindingDataGridView(dgvDevices, lstDevice);
     }
     catch (Exception ex)
     {
         log.Error(ex);
         ShowMsg(MessageBoxIcon.Error, ex.Message);
     }
 }
Example #9
0
 private void btnExit_Click(object sender, EventArgs e)
 {
     try
     {
         SQLiteCommon.CloseDB();
         Application.Exit();
     }
     catch (Exception ex)
     {
         log.Error(ex);
         ShowMsg(MessageBoxIcon.Error, ex.Message);
     }
 }
Example #10
0
 private void loadListUser()
 {
     try
     {
         List <MUser> lstUser = SQLiteCommon.GetALlUsers();
         BindingDataGridView(dgvUserList, lstUser);
     }
     catch (Exception ex)
     {
         log.Error(ex);
         ShowMsg(MessageBoxIcon.Error, ex.Message);
     }
 }
Example #11
0
        public LoginForm()
        {
            InitializeComponent();
            txtUserName.Focus();

            try
            {
                SQLiteCommon.InitDB();
            }
            catch (Exception e)
            {
                log.Error(e);
                ShowMsg(MessageBoxIcon.Error, e.Message);
            }
        }
Example #12
0
        private List <MDevice> searchListDevice()
        {
            var key = this.txtKeySeach.Text.Trim()?.ToLower();

            try
            {
                List <MDevice> lstDevice = SQLiteCommon.GetALlDevices().Where(i => string.IsNullOrEmpty(key) ||
                                                                              i.DeviceName.ToLower().Contains(key) ||
                                                                              i.MacAddress.ToLower().Contains(key)).ToList();
                return(lstDevice);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #13
0
        private void loadCustomerKey()
        {
            try
            {
                List <CustomerKey> lstCusKey = new List <CustomerKey>();
                if (dgvCustomerList.CurrentRow != null)
                {
                    var cusSelected = (MCustomer)dgvCustomerList.CurrentRow.DataBoundItem;
                    lstCusKey = SQLiteCommon.GetALlKeysByCusId(cusSelected.ID);
                }

                BindingDataGridView(dgvCusKeys, lstCusKey);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, ex.Message);
            }
        }
Example #14
0
        private List <MCustomer> searchListCustomer()
        {
            var keySeach            = txtKeySeach.Text.Trim().ToLower();
            List <MCustomer> result = new List <MCustomer>();

            try
            {
                List <MCustomer>   lstCustomer  = SQLiteCommon.GetALlCustomers();
                List <KeyDevice>   lstKeyDevice = SQLiteCommon.GetALlKeyDevices();
                List <CustomerKey> lstCusKey    = SQLiteCommon.GetALlCustomerKeys();

                result = (from cus in lstCustomer
                          join cusKey in lstCusKey on cus.ID equals cusKey.CusId into grp
                          from g in grp.DefaultIfEmpty()
                          join keyDevice in lstKeyDevice on g?.KeyCode equals keyDevice.KeyCode into grp1
                          from g1 in grp1.DefaultIfEmpty()
                          select new MCustomer
                {
                    ID = cus.ID,
                    CompanyName = cus.CompanyName,
                    CompanyAddress = cus.CompanyAddress,
                    CompanyMobile = cus.CompanyMobile,
                    CusName = cus.CusName,
                    CusEmail = cus.CusEmail,
                    CusMobile = cus.CusMobile,
                    KeyCode = g != null ? g.KeyCode : "",
                    MachineCode = g1 != null ? g1.MachineCode : "",
                    MacAddress = g1 != null ? g1.MacAddress : "",
                    UserId = g1 != null ? g1.UserId : "",
                    CreateDate = g1?.CreateDate
                }).Where(i => (string.IsNullOrEmpty(keySeach) ||
                               i.KeyCode.ToLower().Contains(keySeach) || i.CusName.ToLower().Contains(keySeach) || i.MacAddress.ToLower().Contains(keySeach))).ToList();

                return(result);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }
Example #15
0
        private bool isDeviceExist(string macAddress)
        {
            bool result = false;

            try
            {
                string sql = string.Format("SELECT * FROM M_DEVICES WHERE LOWER(MACADDRESS) = '{0}'", macAddress.ToLower());
                var    res = SQLiteCommon.ExecuteSqlWithResult(sql);

                if (res != null && res.HasRows)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(result);
        }
Example #16
0
        private bool isUserExist(string userName)
        {
            bool result = false;

            try
            {
                string sql = string.Format("SELECT * FROM M_USERS WHERE LOWER(USERID) = '{0}'", userName.ToLower());
                var    res = SQLiteCommon.ExecuteSqlWithResult(sql);

                if (res != null && res.HasRows)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(result);
        }
Example #17
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            SQLiteCommon.BeginTran();

            try
            {
                string sql = "DELETE FROM M_USERS WHERE USERID = '{0}'";
                sql = string.Format(sql, paramUpdate.UserId);
                SQLiteCommon.ExecuteSqlNonResult(sql);
                SQLiteCommon.CommitTran();
                ShowMsg(MessageBoxIcon.Information, DELETE_USER_SUCCESS);
                this.isSuccess    = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, DELETE_USER_FAIL + " : " + ex.Message);
            }
        }
Example #18
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string userName = this.txtUserName.Text.Trim();
                string passWord = this.txtPassword.Text.Trim();

                if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord))
                {
                    ShowMsg(MessageBoxIcon.Warning, "Please input UserName Or Password!");
                    this.txtUserName.Focus();
                    return;
                }

                string sql    = string.Format("SELECT * FROM M_USERS WHERE LOWER(USERID)='{0}' AND PASSWORD='******'", userName.ToLower(), passWord);
                var    result = SQLiteCommon.ExecuteSqlWithResult(sql);

                if (result != null && result.HasRows)
                {
                    CURRENT_USER = userName;
                    MainForm mainForm = new MainForm();
                    mainForm.Show();
                    this.Hide();
                }
                else
                {
                    ShowMsg(MessageBoxIcon.Warning, "UserName Or Password Wrong! Please input this again!");
                    this.txtUserName.Focus();
                    this.txtPassword.Text = string.Empty;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, ex.Message);
            }
        }
Example #19
0
        private void loadListCustomer()
        {
            var      keySeach = txtKeySeach.Text.Trim().ToLower();
            DateTime dateFrom = dtpFrom?.Value ?? DateTime.MinValue;
            DateTime dateTo   = dtpTo?.Value ?? DateTime.MinValue;

            dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 0);
            dateTo   = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59);

            try
            {
                List <MCustomer>   lstCustomer  = SQLiteCommon.GetALlCustomers();
                List <KeyDevice>   lstKeyDevice = SQLiteCommon.GetALlKeyDevices();
                List <CustomerKey> lstCusKey    = SQLiteCommon.GetALlCustomerKeys();

                var lstCusKeyGroup = lstCusKey.GroupBy(i => new { i.CusId, i.KeyCode });

                var data = (from cus in lstCustomer
                            join cusKey in lstCusKeyGroup on cus.ID equals cusKey.Key.CusId into grp
                            from g in grp.DefaultIfEmpty()
                            join keyDevice in lstKeyDevice on g?.Key.KeyCode equals keyDevice.KeyCode into grp1
                            from g1 in grp1.DefaultIfEmpty()
                            select new MCustomer
                {
                    ID = cus.ID,
                    CompanyName = cus.CompanyName,
                    CompanyAddress = cus.CompanyAddress,
                    CompanyMobile = cus.CompanyMobile,
                    CusName = cus.CusName,
                    CusEmail = cus.CusEmail,
                    CusMobile = cus.CusMobile,
                    KeyCode = g != null ? g.Key.KeyCode : "",
                    MachineCode = g1 != null ? g1.MachineCode : "",
                    MacAddress = g1 != null ? g1.MacAddress : "",
                    UserId = g1 != null ? g1.UserId : "",
                    CreateDate = g1?.CreateDate
                }).Where(i => (string.IsNullOrEmpty(keySeach) ||
                               i.KeyCode.ToLower().Contains(keySeach) || i.CusName.ToLower().Contains(keySeach) || i.MacAddress.ToLower().Contains(keySeach) ||
                               i.MachineCode.ToLower().Contains(keySeach)) &&
                         (string.IsNullOrEmpty(i.KeyCode) || (i.CreateDate >= dateFrom && i.CreateDate <= dateTo)))
                           .GroupBy(i => new { i.ID, i.CompanyName, i.CompanyAddress, i.CompanyMobile, i.CusName, i.CusMobile, i.CusEmail })
                           .Select(i => new MCustomer
                {
                    ID             = i.Key.ID,
                    CompanyName    = i.Key.CompanyName,
                    CompanyAddress = i.Key.CompanyAddress,
                    CompanyMobile  = i.Key.CompanyMobile,
                    CusName        = i.Key.CusName,
                    CusEmail       = i.Key.CusEmail,
                    CusMobile      = i.Key.CusMobile
                })
                           .ToList();

                BindingDataGridView(dgvCustomerList, data);

                loadCustomerKey();
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ShowMsg(MessageBoxIcon.Error, ex.Message);
            }
        }
Example #20
0
        private void btnCreateKey_Click(object sender, EventArgs e)
        {
            SQLiteCommon.BeginTran();

            try
            {
                string pathOutput = "keys";
                if (!validateCreateKey())
                {
                    return;
                }

                var machineCode = this.txtMachineCode.Text.Trim();
                var mac1        = this.txtMac1.Text.Trim();
                var mac2        = this.txtMac2.Text.Trim();
                var mac3        = this.txtMac3.Text.Trim();
                var mac4        = this.txtMac4.Text.Trim();
                var mac5        = this.txtMac5.Text.Trim();

                //var key = string.Join(",", machineCode, mac1, mac2, mac3, mac4, mac5);
                var    key          = machineCode;
                string keyEncripted = Cipher.EncryptText(key);

                string fileName = pathOutput + "/" + machineCode.Substring(0, 5) + "_" + DateTime.Now.ToString("yyyyMMdd") + "_keycode.txt";

                if (!Directory.Exists(pathOutput))
                {
                    Directory.CreateDirectory(pathOutput);
                }

                File.WriteAllText(fileName, keyEncripted);

                //INSERT CUSTOMERKEYS
                string sql = "INSERT INTO CUSTOMERKEYS (CUSID, KEYCODE, USERID) VALUES ({0}, '{1}', '{2}')";
                sql = string.Format(sql, currentCustomer.ID, keyEncripted, CURRENT_USER);
                SQLiteCommon.ExecuteSqlNonResult(sql);

                //INSERT KEYDEVICES
                var lstMacs = getListMacInput();
                foreach (var mac in lstMacs)
                {
                    sql = "INSERT INTO KEYDEVICES (KEYCODE, MACHINECODE, MACADDRESS, USERID) VALUES ('{0}','{1}','{2}', '{3}')";
                    sql = string.Format(sql, keyEncripted, machineCode, mac, CURRENT_USER);
                    SQLiteCommon.ExecuteSqlNonResult(sql);
                }

                SQLiteCommon.CommitTran();

                ShowMsg(MessageBoxIcon.Information, "Create Key Success!");
                this.isSuccess    = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
                Process.Start("explorer.exe", pathOutput);
            }
            catch (Exception ex)
            {
                SQLiteCommon.RollBackTran();
                ShowMsg(MessageBoxIcon.Error, "Create Key Fail!");
                log.Error(ex);
            }
        }