private void btnt_search_Click(object sender, EventArgs e)
 {
     if (txtt_search.Text.ToString().Length > 0)
     {
         DataTable data = tables.searchTable(Encrption.trim(txtt_search.Text.ToString()), cbt_search.SelectedItem.ToString());
         if (data.Rows.Count > 0)
         {
             btnt_clear.Show();
             refreshTable(data);
         }
         else
         {
             MessageBox.Show(String.Format("No record(s) found", cbt_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             btnt_clear.Hide();
             txtt_search.Clear();
             txtt_search.Focus();
             refreshTable(tables.getTables());
         }
     }
     else
     {
         MessageBox.Show(String.Format("Please enter keyword to search by {0}", cbt_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
         btnt_clear.Hide();
         txtt_search.Clear();
         txtt_search.Focus();
         refreshTable(tables.getTables());
     }
 }
Example #2
0
        private void Txt_numOfSeat_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                if (validateInput())
                {
                    string floorId     = cb_floor.SelectedValue.ToString();
                    string tableZoneId = cb_zone.SelectedValue.ToString();
                    string tableName   = Encrption.trim(txt_tablename.Text.ToString());
                    string numOfSeat   = Encrption.trim(txt_numOfSeat.Text.ToString());

                    if (this.is_edit.Equals(true))
                    {
                        Tables tables = new Tables(this.table_id, floorId, tableZoneId, tableName, numOfSeat);
                        if (Convert.ToBoolean(tables.updateTable()).Equals(true))
                        {
                            MessageBox.Show("Table has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Close();
                        }
                    }
                    else
                    {
                        Tables tables = new Tables(floorId, tableZoneId, tableName, numOfSeat);
                        if (Convert.ToBoolean(tables.addTable()).Equals(true))
                        {
                            MessageBox.Show("Table has created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Close();
                        }
                    }
                }
            }
        }
 private void SearchEnterPressEventOccure(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar.Equals((char)Keys.Return))
     {
         Customer customer;
         if (txt_search.Text.ToString().Length > 0)
         {
             customer = new Customer();
             DataTable dataTable = customer.searchCustomer(Encrption.trim(txt_search.Text.ToString()), cb_search.SelectedItem.ToString());
             if (dataTable.Rows.Count > 0)
             {
                 btn_clear.Show();
                 this.customerGridViewFormatting(dataTable);
             }
             else
             {
                 MessageBox.Show("No record(s) found", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             customer = null;
             MessageBox.Show(String.Format("Please enter keyword to search by {0}", cb_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txt_search.Focus();
             this.loadCustomer();
         }
     }
 }
 private void EnterKeyPressEventOccure(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar.Equals((char)Keys.Return))
     {
         items = new Items();
         if (txt_search.Text.ToString().Length > 0)
         {
             DataTable data = items.searchItem(Encrption.trim(txt_search.Text.ToString()), cb_search.SelectedItem.ToString());
             if (data.Rows.Count > 0)
             {
                 is_search = true;
                 btn_clear.Show();
                 LoadItems(data);
             }
             else
             {
                 MessageBox.Show("No record(s) found", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             MessageBox.Show(String.Format("Please enter keyword to search by {0}", cb_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txt_search.Focus();
             LoadItems(items.getItems());
         }
     }
 }
 private void txtf_search_TextChanged(object sender, EventArgs e)
 {
     if (txtf_search.Text.ToString().Length > 0)
     {
         refreshFloor(floor.searchFloor(Encrption.trim(txtf_search.Text.ToString())));
     }
     else
     {
         refreshFloor(floor.getFloor());
     }
 }
        private void Txt_zonename_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                string floor_id  = cb_floor.SelectedValue.ToString();
                string zone_name = Encrption.trim(txt_zonename.Text.ToString());

                if (zone_name.Length > 0)
                {
                    if (zone_name.Length > 191)
                    {
                        MessageBox.Show("Zone name is too long", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        if (int.TryParse(zone_name, out int result))
                        {
                            MessageBox.Show("Zone name must be alphabetic", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            if (is_edit.Equals(true))
                            {
                                TableZone tableZone = new TableZone(tablezone_id, floor_id, zone_name);
                                if (Convert.ToBoolean(tableZone.updateTableZone()).Equals(true))
                                {
                                    MessageBox.Show("Table zone updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    this.Close();
                                }
                            }
                            else
                            {
                                TableZone tableZone = new TableZone(floor_id, zone_name);
                                if (Convert.ToBoolean(tableZone.addTableZone()).Equals(true))
                                {
                                    MessageBox.Show("Table zone created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    this.Close();
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please enter zone name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 private void btn_search_Click(object sender, EventArgs e)
 {
     if (txtz_search.Text.ToString().Length > 0)
     {
         btn_clear.Show();
         refreshZone(tableZone.searchZone(Encrption.trim(txtz_search.Text.ToString()), cbz_search.SelectedItem.ToString()));
     }
     else
     {
         MessageBox.Show(String.Format("Please enter keyword to search by {0}", cbz_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
         btn_clear.Hide();
         txtz_search.Clear();
         txtz_search.Focus();
         refreshZone(tableZone.getTableZone());
     }
 }
 private void PressEnterOccure(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Return)
     {
         string category_name = Encrption.trim(txtc_name.Text.ToString());
         if (category_name.Length > 0)
         {
             if (category_name.Length > 191)
             {
                 MessageBox.Show("Category name is too long", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 if (int.TryParse(category_name, out int result))
                 {
                     MessageBox.Show("Category name must be alphabetic", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     if (this.is_edit.Equals(true))
                     {
                         Category category = new Category(this.category_id, category_name, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                         if (Convert.ToBoolean(category.updateCategory()).Equals(true))
                         {
                             MessageBox.Show("Category has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             this.DialogResult = DialogResult.OK;
                             this.Close();
                         }
                     }
                     else
                     {
                         Category category = new Category(category_name, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                         if (Convert.ToBoolean(category.addCategory()).Equals(true))
                         {
                             MessageBox.Show("Category has created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             this.Close();
                         }
                     }
                 }
             }
         }
         else
         {
             MessageBox.Show("Please enter category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #9
0
        private void EnterKeyPressEventOccure(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                if (this.validateUser())
                {
                    if (this.verifiedUser == true)
                    {
                        if (txt_cpassword.Text.ToString().Length > 0)
                        {
                            if (txt_password.Text.ToString().Length < 6 || txt_password.Text.ToString().Length > 20)
                            {
                                string name        = Encrption.trim(txt_name.Text.ToString());
                                string username    = Encrption.trim(txt_username.Text.ToString());
                                string email       = Encrption.trim(txt_email.Text.ToString());
                                string user_role   = Login.user_role;
                                string user_status = Login.user_status;
                                string password    = txt_cpassword.Text.ToString();
                                string created_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                                users = new Users(Login.user_id, name, username, email, password, user_role, user_status, created_at);
                                if (users.updateUser() > 0)
                                {
                                    MessageBox.Show("Account has been updated", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    confirmPasswordlbl.Visible = false;
                                    txt_cpassword.Visible      = false;
                                    txt_password.Clear();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Password must be in between 6 to 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please enter new password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter valid password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
 private void Txt_floor_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Return)
     {
         string floor_name = Encrption.trim(txt_floor.Text.ToString());
         if (floor_name.Length > 0)
         {
             if (floor_name.Length > 191)
             {
                 MessageBox.Show("Floor name is too long", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 if (int.TryParse(floor_name, out int result))
                 {
                     MessageBox.Show("Floor name must be alphabetic", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     if (is_edit.Equals(true))
                     {
                         Floor floor = new Floor(floor_id, floor_name);
                         if (Convert.ToBoolean(floor.updateFloor()).Equals(true))
                         {
                             MessageBox.Show("Floor has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             this.Close();
                         }
                     }
                     else
                     {
                         Floor floor = new Floor(floor_id, floor_name);
                         if (Convert.ToBoolean(floor.addFloor(floor_name)).Equals(true))
                         {
                             MessageBox.Show("Floor has created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             this.Close();
                         }
                     }
                 }
             }
         }
         else
         {
             MessageBox.Show("Please enter floor name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
 private void ZoneSearchEnterEventOccure(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar.Equals((char)Keys.Return))
     {
         if (txtz_search.Text.ToString().Length > 0)
         {
             btn_clear.Show();
             refreshZone(tableZone.searchZone(Encrption.trim(txtz_search.Text.ToString()), cbz_search.SelectedItem.ToString()));
         }
         else
         {
             MessageBox.Show(String.Format("Please enter keyword to search by {0}", cbz_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             btn_clear.Hide();
             txtz_search.Clear();
             txtz_search.Focus();
             refreshZone(tableZone.getTableZone());
         }
     }
 }
        private void EnterKeyPressEventOccure(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                if (this.validateInput())
                {
                    string name            = Encrption.trim(txt_name.Text.ToString());
                    string email           = Encrption.trim(txt_email.Text.ToString());
                    string address         = Encrption.trim(txt_address.Text.ToString());
                    string phone           = Encrption.trim(txt_phone.Text.ToString());
                    string additional_info = Encrption.trim(txt_additionalInfo.Text.ToString());

                    if (this.isCustomerEdit == true)
                    {
                        string updated_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        customer = new Customer(int.Parse(this.customerId), name, phone, address, email, additional_info, updated_at);
                        int result = customer.updateCustomer();
                        if (result > 0)
                        {
                            MessageBox.Show("Customer has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.nullInputFied();
                            this.Close();
                        }
                    }
                    else
                    {
                        string created_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        string updated_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                        customer = new Customer(name, phone, address, email, additional_info, created_at, updated_at);
                        int result = customer.addCustomer();
                        if (result > 0)
                        {
                            MessageBox.Show("Customer has created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.nullInputFied();
                            this.Close();
                        }
                    }
                }
            }
        }
        private void loadKitchen(string search = null)
        {
            kitchen = new Kitchen();
            List <Tuple <string, string, string> > kitchenList = new List <Tuple <string, string, string> >();

            if (search != null && Encrption.trim(search).Length > 0)
            {
                kitchenList = kitchen.getKitchens(kitchen.searchKitchen(search));
            }
            else
            {
                kitchenList = kitchen.getKitchens();
            }
            dgv_kitchen.Rows.Clear();
            int sno = 0;

            foreach (var tuple in kitchenList)
            {
                dgv_kitchen.Rows.Add(new object[] { ++sno, tuple.Item1, tuple.Item2, tuple.Item3 });
            }
        }
Example #14
0
 private void CheckEnterKeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Return)
     {
         string username = Encrption.trim(txt_username.Text.ToString());
         string password = Encrption.trim(txt_password.Text.ToString());
         if (validateInput())
         {
             DataTable data = login.Login_action(username, password);
             if (data.Rows.Count > 0)
             {
                 if (Login.user_status.Equals("1"))
                 {
                     MainPanel mainPanel = new MainPanel();
                     mainPanel.Owner = this;
                     this.Hide();
                     mainPanel.Show();
                 }
                 else if (Login.user_status.Equals("2"))
                 {
                     MessageBox.Show("Your account has been de-active");
                 }
                 else if (Login.user_status.Equals("3"))
                 {
                     MessageBox.Show("Your account has been suspended");
                 }
                 else
                 {
                     MessageBox.Show("Your account has been terminated");
                 }
                 this.emptyInputField();
             }
             else
             {
                 MessageBox.Show("Invalid login id or password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 this.emptyInputField();
             }
         }
     }
 }
        public UserED()
        {
            InitializeComponent();

            txt_name.KeyPress        += EnterKeyPressEventOccure;
            txt_email.KeyPress       += EnterKeyPressEventOccure;
            txt_username.KeyPress    += EnterKeyPressEventOccure;
            txt_password.KeyPress    += EnterKeyPressEventOccure;
            txt_newPassword.KeyPress += EnterKeyPressEventOccure;

            this.Text = "Add User";

            users = new Users();

            cb_userRole.DataSource    = users.getUserRole();
            cb_userRole.ValueMember   = "code";
            cb_userRole.DisplayMember = "name";
            cb_userRole.DropDownStyle = ComboBoxStyle.DropDownList;

            DataTable data = users.getUserStatus();

            foreach (DataRow row in data.Rows)
            {
                row["name"] = Encrption.UppercaseFirst(row["name"].ToString());
            }

            cb_userStatus.DataSource    = data;
            cb_userStatus.ValueMember   = "id";
            cb_userStatus.DisplayMember = "name";
            cb_userStatus.DropDownStyle = ComboBoxStyle.DropDownList;

            passwordlbl.Text = "Password";
            confirmPasswordlbl.Hide();
            txt_newPassword.Hide();

            btn_update.Text = "ADD";
            btn_delete.Text = "CANCEL";

            is_edit = false;
        }
Example #16
0
        public EmployeeED()
        {
            InitializeComponent();

            txt_name.KeyPress       += EnterKeyPressEventOccure;
            txt_email.KeyPress      += EnterKeyPressEventOccure;
            txt_address.KeyPress    += EnterKeyPressEventOccure;
            txt_fathername.KeyPress += EnterKeyPressEventOccure;
            txt_mobile.KeyPress     += EnterKeyPressEventOccure;
            txt_nic.KeyPress        += EnterKeyPressEventOccure;


            this.isEditEmployee = false;
            this.removeImage    = false;
            this.fileExt        = "";
            this.filePath       = "";

            users = new Users();

            DataTable dataUserRole = users.getUserRole();

            cb_role.DataSource    = dataUserRole;
            cb_role.ValueMember   = "code";
            cb_role.DisplayMember = "name";
            cb_role.SelectedIndex = 0;

            DataTable data = users.getUserStatus();

            foreach (DataRow row in data.Rows)
            {
                row["name"] = Encrption.UppercaseFirst(row["name"].ToString());
            }
            cb_status.DataSource    = data;
            cb_status.ValueMember   = "id";
            cb_status.DisplayMember = "name";
            cb_status.SelectedIndex = 0;

            this.appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\EmployeesImages\";
        }
        private void btn_search_Click(object sender, EventArgs e)
        {
            Customer customer = new Customer();

            if (txt_search.Text.ToString().Length > 0)
            {
                DataTable dataTable = customer.searchCustomer(Encrption.trim(txt_search.Text.ToString()), cb_search.SelectedItem.ToString());
                if (dataTable.Rows.Count > 0)
                {
                    btn_clear.Show();
                    this.customerGridViewFormatting(dataTable);
                }
                else
                {
                    MessageBox.Show("No record(s) found", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show(String.Format("Please enter keyword to search by {0}", cb_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_search.Focus();
                this.loadCustomer();
            }
        }
        private bool validateUser()
        {
            int           isError = 0;
            StringBuilder builder = new StringBuilder();

            if (txt_name.Text.ToString().Length > 0)
            {
                if (txt_name.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("Name is too long").AppendLine();
                }
                else
                {
                    if (!Regex.IsMatch(txt_name.Text, @"^[A-Za-z ]+$"))
                    {
                        isError++;
                        builder.Append("Name contain only character").AppendLine();
                    }

                    //if(Regex.IsMatch(txt_name.Text, "^[0-9]+$"))
                    //{
                    //    isError++;
                    //    builder.Append("Name cannot contain digits").AppendLine();
                    //}
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_email.Text.ToString().Length > 0)
            {
                if (Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    if (txt_email.Text.ToString().Length > 191)
                    {
                        isError++;
                        builder.Append("Email is too long").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter  email").AppendLine();
            }

            if (txt_username.Text.ToString().Length > 0)
            {
                if (txt_username.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("login id is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter login id").AppendLine();
            }

            if (!is_edit.Equals(true))
            {
                if (txt_password.Text.ToString().Length > 0)
                {
                    if (txt_password.Text.ToString().Length < 6 || txt_password.Text.ToString().Length > 20)
                    {
                        isError++;
                        builder.Append("Password must be in between 6 to 20 characters").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter password").AppendLine();
                }
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public UserED(int user_id)
        {
            InitializeComponent();

            txt_name.KeyPress        += EnterKeyPressEventOccure;
            txt_email.KeyPress       += EnterKeyPressEventOccure;
            txt_username.KeyPress    += EnterKeyPressEventOccure;
            txt_password.KeyPress    += EnterKeyPressEventOccure;
            txt_newPassword.KeyPress += EnterKeyPressEventOccure;

            //this.Text = name.ToUpper();

            this.verifiedUser = false;
            this.role         = Login.user_role;

            this.selectedUserId = user_id;

            users = new Users(user_id);

            DataTable currentUser = users.getUserById();

            cb_userRole.DataSource    = users.getUserRole();
            cb_userRole.ValueMember   = "code";
            cb_userRole.DisplayMember = "name";
            cb_userRole.DropDownStyle = ComboBoxStyle.DropDownList;

            DataTable data = users.getUserStatus();

            foreach (DataRow row in data.Rows)
            {
                row["name"] = Encrption.UppercaseFirst(row["name"].ToString());
            }
            cb_userStatus.DataSource    = data;
            cb_userStatus.ValueMember   = "id";
            cb_userStatus.DisplayMember = "name";
            cb_userStatus.DropDownStyle = ComboBoxStyle.DropDownList;

            passwordlbl.Visible        = false;
            txt_password.Visible       = false;
            confirmPasswordlbl.Visible = false;
            txt_newPassword.Visible    = false;
            btn_delete.Enabled         = false;

            is_edit = true;

            if (currentUser.Rows.Count > 0)
            {
                this.Text = currentUser.Rows[0]["name"].ToString();

                txt_name.Text               = currentUser.Rows[0]["name"].ToString();
                txt_username.Text           = currentUser.Rows[0]["username"].ToString();
                login_id                    = currentUser.Rows[0]["username"].ToString();
                txt_email.Text              = currentUser.Rows[0]["email"].ToString();
                cb_userRole.SelectedValue   = currentUser.Rows[0]["user_role_code"].ToString();
                cb_userStatus.SelectedValue = currentUser.Rows[0]["user_status_id"].ToString();


                if (role.Equals("admin"))
                {
                    passwordlbl.Visible  = true;
                    txt_password.Visible = true;

                    if (this.selectedUserId.Equals(Login.user_id))
                    {
                        passwordlbl.Text   = "Old Password";
                        btn_delete.Enabled = false;
                    }
                    else
                    {
                        passwordlbl.Text   = "Password";
                        btn_delete.Enabled = true;
                    }
                }
            }
        }
Example #20
0
        private bool validateUser()
        {
            int isError = 0;

            StringBuilder builder = new StringBuilder();

            if (txt_email.Text.ToString().Length > 0)
            {
                if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter  email").AppendLine();
            }



            if (txt_name.Text.ToString().Length > 0)
            {
                if (Encrption.Is_Alphabetic(txt_name.Text.ToString()))
                {
                    if (txt_name.Text.ToString().Length > 191)
                    {
                        isError++;
                        builder.Append("Name is too long").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Name must be alphabetic").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_username.Text.ToString().Length > 0)
            {
                if (txt_username.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("Username is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter username").AppendLine();
            }

            if (txt_password.Text.ToString().Length > 0)
            {
                if (txt_password.Text.ToString().Length < 6 || txt_password.Text.ToString().Length > 20)
                {
                    isError++;
                    builder.Append("Password must be in between 6 to 20 characters").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter password").AppendLine();
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #21
0
        private void EnterKeyPressEventOccure(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                if (this.validateInput())
                {
                    string name        = Encrption.trim(txt_name.Text.ToString());
                    string father_name = Encrption.trim(txt_fathername.Text.ToString());
                    string email       = Encrption.trim(txt_email.Text.ToString());
                    string mobile      = Encrption.trim(txt_mobile.Text.ToString());
                    string nic         = Encrption.trim(txt_nic.Text.ToString());
                    string address     = Encrption.trim(txt_address.Text.ToString());
                    string user_role   = cb_role.SelectedValue.ToString();
                    string user_status = cb_status.SelectedValue.ToString();
                    string created_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    string updated_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                    if (this.isEditEmployee == true)
                    {
                        if (this.filePath.Equals("") && this.fileExt.Equals(""))
                        {
                            if (this.removeImage == true)
                            {
                                employee = new Employee(int.Parse(this.employeeId), name, father_name, address, email, mobile, nic, user_role, "", user_status, updated_at);
                            }
                            else
                            {
                                employee = new Employee(int.Parse(this.employeeId), name, father_name, address, email, mobile, nic, user_role, this.previousImage, user_status, updated_at);
                            }
                            if (employee.updateEmployee() > 0)
                            {
                                MessageBox.Show("Record has been updated");
                                this.Close();
                            }
                        }
                        else
                        {
                            string file = Guid.NewGuid() + "_" + this.employeeId + this.fileExt;
                            this.appPath = this.appPath + file;
                            File.Copy(this.filePath, this.appPath);
                            employee = new Employee(int.Parse(this.employeeId), name, father_name, address, email, mobile, nic, user_role, file, user_status, updated_at);
                            if (employee.updateEmployee() > 0)
                            {
                                MessageBox.Show("Record has been updated");
                                this.Close();
                            }
                        }
                    }
                    else
                    {
                        employee = new Employee(name, father_name, address, email, mobile, nic, user_role, "", user_status, created_at, updated_at);
                        int result = employee.addEmployee();
                        if (result > 0)
                        {
                            if (this.filePath.Equals("") && this.fileExt.Equals(""))
                            {
                                MessageBox.Show(String.Format("{0} Record has been inserted.", result));
                                this.nullInputFied();
                                this.Close();
                            }
                            else
                            {
                                string employeeId = employee.getLastInsertedItemId();
                                string file       = Guid.NewGuid() + "_" + employeeId + this.fileExt;
                                this.appPath = this.appPath + file;
                                File.Copy(this.filePath, this.appPath);

                                employee = null;
                                employee = new Employee(employeeId, file);
                                int check = employee.updateItemImage();
                                if (check > 0)
                                {
                                    MessageBox.Show("Record has been inserted");
                                    this.nullInputFied();
                                    this.Close();
                                }
                            }
                        }
                    }
                }
            }
        }
        private bool validateInput()
        {
            StringBuilder builder = new StringBuilder();
            int           isError = 0;

            if (txt_name.Text.ToString().Length > 0)
            {
                if (this.IsDigitsOnly(txt_name.Text.ToString()))
                {
                    isError++;
                    builder.Append("Name must be alphabetic").AppendLine();
                }
                else
                {
                    if (txt_name.Text.ToString().Length > 191)
                    {
                        isError++;
                        builder.Append("Name is too long").AppendLine();
                    }
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_email.Text.ToString().Length > 0)
            {
                if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter  email").AppendLine();
            }

            Customer customer = new Customer();

            if (this.isCustomerEdit == true)
            {
                if (txt_phone.Text.ToString().Length > 0)
                {
                    if (this.IsDigitsOnly(txt_phone.Text.ToString()))
                    {
                        if (txt_phone.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("Phone number should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (!this.previous_phone.Equals(txt_phone.Text.ToString()))
                            {
                                if (customer.checkPhoneAlreadyExist(txt_phone.Text.ToString()))
                                {
                                    isError++;
                                    builder.Append("Phone number already exist").AppendLine();
                                }
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Phone must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter phone").AppendLine();
                }
            }
            else
            {
                if (txt_phone.Text.ToString().Length > 0)
                {
                    if (this.IsDigitsOnly(txt_phone.Text.ToString()))
                    {
                        if (txt_phone.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("Phone number should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (customer.checkPhoneAlreadyExist(txt_phone.Text.ToString()))
                            {
                                isError++;
                                builder.Append("Phone number already exist").AppendLine();
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Phone must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter phone").AppendLine();
                }
            }



            if (txt_address.Text.Length > 0)
            {
                if (txt_address.Text.Length > 191)
                {
                    isError++;
                    builder.Append("Address is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter address").AppendLine();
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
        private void btn_add_Click(object sender, EventArgs e)
        {
            if (this.validateInput())
            {
                string name           = Encrption.trim(txt_name.Text.ToString());
                string categoryId     = cb_category.SelectedValue.ToString();
                string desc           = Encrption.trim(txt_desc.Text.ToString());
                string sale_price     = Encrption.trim(txt_saleprice.Text.ToString());
                string purchase_price = Encrption.trim(txt_purchase.Text.ToString());
                string discount       = Encrption.trim(txt_discount.Text.ToString());
                string apply_discount = "0";

                if (chk_ad.Checked == true)
                {
                    apply_discount = "1";
                }
                string apply_tax = "0";
                if (chk_at.Checked == true)
                {
                    apply_tax = "1";
                }
                string is_kitchen = "0";
                if (chk_ktch.Checked == true)
                {
                    is_kitchen = "1";
                }

                string created_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string updated_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                if (isEditItem == true)
                {
                    try
                    {
                        string file;
                        if (this.filePath.Equals(""))
                        {
                            file  = this.previousImage;
                            items = new Items(this.itemId, categoryId, name, desc, sale_price, purchase_price, discount, apply_discount, apply_tax, is_kitchen, file, created_at, updated_at);
                            int result = items.updateItem();
                            if (result > 0)
                            {
                                MessageBox.Show("Item has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                        }
                        else
                        {
                            file  = Guid.NewGuid() + "_" + this.itemId + this.fileExt;
                            items = new Items(this.itemId, categoryId, name, desc, sale_price, purchase_price, discount, apply_discount, apply_tax, is_kitchen, file, created_at, updated_at);
                            int result = items.updateItem();
                            if (result > 0)
                            {
                                MessageBox.Show("Item has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                string checkFilePath = this.appPath + file;
                                File.Copy(this.filePath, checkFilePath, true);
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    string imagePath = "";
                    items = new Items(categoryId, name, desc, sale_price, purchase_price, discount, apply_discount, apply_tax, is_kitchen, imagePath, created_at, updated_at);
                    int result = items.addItem();
                    if (result > 0)
                    {
                        if (this.filePath.Equals("") && this.fileExt.Equals(""))
                        {
                            MessageBox.Show("Item has created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.DialogResult = DialogResult.OK;
                            this.nullInputFied();
                            this.Close();
                        }
                        else
                        {
                            string itemId = items.getLastInsertedItemId();
                            string file   = Guid.NewGuid() + "_" + itemId + this.fileExt;
                            this.appPath = this.appPath + file;
                            File.Copy(this.filePath, this.appPath);

                            items = null;
                            items = new Items(itemId, file);
                            int check = items.updateItemImage();
                            if (check > 0)
                            {
                                MessageBox.Show("Item has created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.DialogResult = DialogResult.OK;
                                this.nullInputFied();
                                this.Close();
                            }
                        }
                    }
                }
            }
        }
Example #24
0
        private void btn_add_Click(object sender, EventArgs e)
        {
            if (this.validateInput())
            {
                string name        = Encrption.trim(txt_name.Text.ToString());
                string father_name = Encrption.trim(txt_fathername.Text.ToString());
                string email       = Encrption.trim(txt_email.Text.ToString());
                string mobile      = Encrption.trim(txt_mobile.Text.ToString());
                string nic         = Encrption.trim(txt_nic.Text.ToString());
                string address     = Encrption.trim(txt_address.Text.ToString());
                string user_role   = cb_role.SelectedValue.ToString();
                string user_status = cb_status.SelectedValue.ToString();
                string created_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string updated_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (this.isEditEmployee == true)
                {
                    if (this.filePath.Equals("") && this.fileExt.Equals(""))
                    {
                        if (this.removeImage == true)
                        {
                            employee = new Employee(int.Parse(this.employeeId), name, father_name, address, email, mobile, nic, user_role, "", user_status, updated_at);
                        }
                        else
                        {
                            employee = new Employee(int.Parse(this.employeeId), name, father_name, address, email, mobile, nic, user_role, this.previousImage, user_status, updated_at);
                        }
                        if (employee.updateEmployee() > 0)
                        {
                            MessageBox.Show("Employee has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                    }
                    else
                    {
                        string file = Guid.NewGuid() + "_" + this.employeeId + this.fileExt;
                        this.appPath = this.appPath + file;
                        File.Copy(this.filePath, this.appPath);
                        employee = new Employee(int.Parse(this.employeeId), name, father_name, address, email, mobile, nic, user_role, file, user_status, updated_at);
                        if (employee.updateEmployee() > 0)
                        {
                            MessageBox.Show("Employee has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                    }
                }
                else
                {
                    employee = new Employee(name, father_name, address, email, mobile, nic, user_role, "", user_status, created_at, updated_at);
                    int result = employee.addEmployee();
                    if (result > 0)
                    {
                        if (this.filePath.Equals("") && this.fileExt.Equals(""))
                        {
                            MessageBox.Show("Employee has inserted successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.nullInputFied();
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            string employeeId = employee.getLastInsertedItemId();
                            string file       = Guid.NewGuid() + "_" + employeeId + this.fileExt;
                            this.appPath = this.appPath + file;
                            File.Copy(this.filePath, this.appPath);

                            employee = null;
                            employee = new Employee(employeeId, file);
                            int check = employee.updateItemImage();
                            if (check > 0)
                            {
                                MessageBox.Show("Employee has inserted successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.nullInputFied();
                                this.DialogResult = DialogResult.OK;
                                this.Close();
                            }
                        }
                    }
                }
            }
        }
 private void SearchPressEnterEventOccure(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (Char)Keys.Return)
     {
         Employee employee = new Employee();
         if (cb_search.SelectedItem.ToString().Equals("Name"))
         {
             if (txt_search.Text.ToString().Length > 0)
             {
                 DataTable data = employee.searchEmployee(Encrption.trim(txt_search.Text.ToString()), cb_search.SelectedItem.ToString());
                 if (data.Rows.Count > 0)
                 {
                     btn_clear.Show();
                     this.employeeGridViewFormatting(data);
                 }
                 else
                 {
                     MessageBox.Show("No record(s) found", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             else
             {
                 MessageBox.Show(String.Format("Please enter keyword to search by {0}", cb_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 txt_search.Focus();
                 this.loadEmployee();
             }
         }
         else if (cb_search.SelectedItem.ToString().Equals("Role"))
         {
             if (txt_search.Text.ToString().Length > 0)
             {
                 DataTable data = employee.searchEmployee(Encrption.trim(txt_search.Text.ToString()), cb_search.SelectedItem.ToString());
                 if (data.Rows.Count > 0)
                 {
                     btn_clear.Show();
                     this.employeeGridViewFormatting(data);
                 }
                 else
                 {
                     MessageBox.Show("No record(s) found", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             else
             {
                 MessageBox.Show(String.Format("Please enter keyword to search by {0}", cb_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 txt_search.Focus();
                 this.loadEmployee();
             }
         }
         else if (cb_search.SelectedItem.ToString().Equals("Mobile"))
         {
             if (txt_search.Text.ToString().Length > 0)
             {
                 DataTable data = employee.searchEmployee(Encrption.trim(txt_search.Text.ToString()), cb_search.SelectedItem.ToString());
                 if (data.Rows.Count > 0)
                 {
                     btn_clear.Show();
                     this.employeeGridViewFormatting(data);
                 }
                 else
                 {
                     MessageBox.Show("No record(s) found", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             else
             {
                 MessageBox.Show(String.Format("Please enter keyword to search by {0}", cb_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 txt_search.Focus();
                 this.loadEmployee();
             }
         }
         else if (cb_search.SelectedItem.ToString().Equals("Nic"))
         {
             if (txt_search.Text.ToString().Length > 0)
             {
                 DataTable data = employee.searchEmployee(Encrption.trim(txt_search.Text.ToString()), cb_search.SelectedItem.ToString());
                 if (data.Rows.Count > 0)
                 {
                     btn_clear.Show();
                     this.employeeGridViewFormatting(data);
                 }
                 else
                 {
                     MessageBox.Show("No record(s) found", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             else
             {
                 MessageBox.Show(String.Format("Please enter keyword to search by {0}", cb_search.SelectedItem.ToString()), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 txt_search.Focus();
                 this.loadEmployee();
             }
         }
         else
         {
             employee = null;
         }
     }
 }
Example #26
0
        private bool validateInput()
        {
            StringBuilder builder = new StringBuilder();
            int           isError = 0;

            if (txt_name.Text.ToString().Length > 0)
            {
                if (!Encrption.Is_Alphabetic(txt_name.Text.ToString()))
                {
                    isError++;
                    builder.Append("Name must be alphabetic").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_fathername.Text.ToString().Length > 0)
            {
                if (!Encrption.Is_Alphabetic(txt_fathername.Text.ToString()))
                {
                    isError++;
                    builder.Append("Father name must be alphabetic").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter father name").AppendLine();
            }

            if (txt_email.Text.ToString().Length > 0)
            {
                if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter email").AppendLine();
            }

            Employee employee = new Employee();

            if (this.isEditEmployee == true)
            {
                // Mobile
                if (txt_mobile.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_mobile.Text.ToString(), out double result))
                    {
                        if (txt_mobile.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("mobile lenght should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (!this.mobile_no.Equals(txt_mobile.Text.ToString()))
                            {
                                if (employee.checkPhoneAlreadyExist(txt_mobile.Text.ToString()))
                                {
                                    isError++;
                                    builder.Append("Mobile number already exists").AppendLine();
                                }
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Mobile number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("please enter mobile number").AppendLine();
                }

                // Nic
                if (txt_nic.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_nic.Text.ToString(), out double result))
                    {
                        if (txt_nic.Text.ToString().Length != 13)
                        {
                            isError++;
                            builder.Append("Nic lenght should be 13 digits").AppendLine();
                        }
                        else
                        {
                            if (!this.cnic_no.Equals(txt_nic.Text.ToString()))
                            {
                                if (employee.checkNicAlreadyExist(txt_nic.Text.ToString()))
                                {
                                    isError++;
                                    builder.Append("Nic number already exist").AppendLine();
                                }
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Nic number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter nic number").AppendLine();
                }
            }
            else
            {
                // Mobile
                if (txt_mobile.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_mobile.Text.ToString(), out double result))
                    {
                        if (txt_mobile.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("mobile lenght should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (employee.checkPhoneAlreadyExist(txt_mobile.Text.ToString()))
                            {
                                isError++;
                                builder.Append("Mobile number already exists").AppendLine();
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Mobile number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("please enter mobile number").AppendLine();
                }

                // Nic
                if (txt_nic.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_nic.Text.ToString(), out double result))
                    {
                        if (txt_nic.Text.ToString().Length != 13)
                        {
                            isError++;
                            builder.Append("Nic lenght should be 13 digits").AppendLine();
                        }
                        else
                        {
                            if (employee.checkNicAlreadyExist(txt_nic.Text.ToString()))
                            {
                                isError++;
                                builder.Append("Nic number already exist").AppendLine();
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Nic number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter nic number").AppendLine();
                }
            }

            if (txt_address.Text.Length > 0)
            {
                if (txt_address.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("Address is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("please enter address").AppendLine();
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
        private void btn_update_Click(object sender, EventArgs e)
        {
            if (is_edit.Equals(true))
            {
                if (role.Equals("admin"))
                {
                    if (this.validateUser())
                    {
                        if (this.selectedUserId.Equals(Login.user_id))
                        {
                            if (this.verifiedUser == true)
                            {
                                if (txt_newPassword.Text.ToString().Length > 0)
                                {
                                    if (txt_newPassword.Text.ToString().Length >= 6 && txt_newPassword.Text.ToString().Length <= 20)
                                    {
                                        // Admin update operation
                                        string name        = Encrption.trim(txt_name.Text.ToString());
                                        string username    = Encrption.trim(txt_username.Text.ToString());
                                        string email       = Encrption.trim(txt_email.Text.ToString());
                                        string user_role   = cb_userRole.SelectedValue.ToString();
                                        string user_status = cb_userStatus.SelectedValue.ToString();
                                        string password    = Encrption.trim(txt_newPassword.Text.ToString());
                                        string created_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                                        users = new Users(Login.user_id, name, username, email, password, user_role, user_status, created_at);
                                        if (users.updateUser() > 0)
                                        {
                                            MessageBox.Show("User has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            this.DialogResult = DialogResult.OK;
                                            this.Close();
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Password must be in between 6 to 20 character");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Please enter new password");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Please enter password to verify");
                            }
                        }
                        else
                        {
                            if (login_id == txt_username.Text.ToString())
                            {
                                // Other update operation
                                string name        = Encrption.trim(txt_name.Text.ToString());
                                string username    = Encrption.trim(txt_username.Text.ToString());
                                string email       = Encrption.trim(txt_email.Text.ToString());
                                string user_role   = cb_userRole.SelectedValue.ToString();
                                string user_status = cb_userStatus.SelectedValue.ToString();
                                string password    = Encrption.trim(txt_password.Text.ToString());
                                string created_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                                users = new Users(this.selectedUserId, name, username, email, password, user_role, user_status, created_at);
                                if (users.updateUser() > 0)
                                {
                                    MessageBox.Show("User has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    this.DialogResult = DialogResult.OK;
                                    this.Close();
                                }
                            }
                            else
                            {
                                users = new Users();
                                if (users.is_LoginIdAlreadyExist(txt_username.Text.ToString()))
                                {
                                    MessageBox.Show("Login id already taken", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    // Other update operation
                                    string name        = Encrption.trim(txt_name.Text.ToString());
                                    string username    = Encrption.trim(txt_username.Text.ToString());
                                    string email       = Encrption.trim(txt_email.Text.ToString());
                                    string user_role   = cb_userRole.SelectedValue.ToString();
                                    string user_status = cb_userStatus.SelectedValue.ToString();
                                    string password    = Encrption.trim(txt_password.Text.ToString());
                                    string created_at  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                                    users = new Users(this.selectedUserId, name, username, email, password, user_role, user_status, created_at);
                                    if (users.updateUser() > 0)
                                    {
                                        MessageBox.Show("User has updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        this.Close();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (this.validateUser().Equals(true))
                {
                    users = new Users();
                    if (users.is_LoginIdAlreadyExist(txt_username.Text.ToString()))
                    {
                        MessageBox.Show("The Login Id is already in use", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        string name       = Encrption.trim(txt_name.Text.ToString());
                        string username   = Encrption.trim(txt_username.Text.ToString());
                        string email      = Encrption.trim(txt_email.Text.ToString());
                        string user_role  = cb_userRole.SelectedValue.ToString();
                        string status     = cb_userStatus.SelectedValue.ToString();
                        string password   = Encrption.trim(txt_password.Text.ToString());
                        string created_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        users = null;
                        users = new Users(0, name, username, email, password, user_role, status, created_at);
                        int result = users.addUser();
                        if (result > 0)
                        {
                            MessageBox.Show("The user has created successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.nullInputField();
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            this.nullInputField();
                        }
                    }
                }
            }
        }
Example #28
0
        public EmployeeED(string employee_id)
        {
            InitializeComponent();

            txt_name.KeyPress       += EnterKeyPressEventOccure;
            txt_email.KeyPress      += EnterKeyPressEventOccure;
            txt_address.KeyPress    += EnterKeyPressEventOccure;
            txt_fathername.KeyPress += EnterKeyPressEventOccure;
            txt_mobile.KeyPress     += EnterKeyPressEventOccure;
            txt_nic.KeyPress        += EnterKeyPressEventOccure;

            this.isEditEmployee = true;
            this.removeImage    = false;
            this.employeeId     = employee_id;
            this.fileExt        = "";
            this.filePath       = "";

            btn_add.Text    = "UPDATE";
            btn_cancel.Text = "DELETE";

            users = new Users();

            DataTable dataUserRole = users.getUserRole();

            cb_role.DataSource    = dataUserRole;
            cb_role.ValueMember   = "code";
            cb_role.DisplayMember = "name";
            cb_role.SelectedIndex = 0;


            DataTable data = users.getUserStatus();

            foreach (DataRow row in data.Rows)
            {
                row["name"] = Encrption.UppercaseFirst(row["name"].ToString());
            }

            cb_status.DataSource    = data;
            cb_status.ValueMember   = "id";
            cb_status.DisplayMember = "name";
            cb_status.SelectedIndex = 0;

            this.appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\EmployeesImages\";

            employee = new Employee(employee_id);
            DataTable dataTable = employee.getEmployeeById();

            if (dataTable.Rows.Count > 0)
            {
                this.employeeName       = dataTable.Rows[0]["name"].ToString();
                txt_name.Text           = dataTable.Rows[0]["name"].ToString();
                txt_fathername.Text     = dataTable.Rows[0]["father_name"].ToString();
                txt_address.Text        = dataTable.Rows[0]["address"].ToString();
                txt_email.Text          = dataTable.Rows[0]["email"].ToString();
                txt_mobile.Text         = dataTable.Rows[0]["mobile_no"].ToString();
                this.mobile_no          = dataTable.Rows[0]["mobile_no"].ToString();
                txt_nic.Text            = dataTable.Rows[0]["cnic_no"].ToString();
                this.cnic_no            = dataTable.Rows[0]["cnic_no"].ToString();
                cb_role.SelectedValue   = dataTable.Rows[0]["user_role_code"].ToString();
                cb_status.SelectedValue = dataTable.Rows[0]["user_status_id"].ToString();
                this.previousImage      = dataTable.Rows[0]["profile_image"].ToString();
                if (!dataTable.Rows[0]["profile_image"].ToString().Equals(""))
                {
                    image.Image = Bitmap.FromFile(Path.Combine(this.appPath, dataTable.Rows[0]["profile_image"].ToString()));
                }
            }
            else
            {
                MessageBox.Show(String.Format("Employee contain id : {0} were not found", employee_id), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }