Example #1
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 #2
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 #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 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 #5
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 #6
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 #7
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 #8
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);
            }
        }