Example #1
0
        void Btn_okClick(object sender, EventArgs e)
        {
            DataTable dt = Functions.GetTable("select name, password from "
                                              + Program.ModName_lcns + "_users where name = '" + Program.currentUSER + "'");

            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("Old password did not match.");
                return;
            }
            else
            {
                string decryptedPassword = StringCipher.Decrypt(dt.Rows[0]["password"].ToString(), Program.EncryptionKey);
                if (string.Compare(decryptedPassword, txb_old_password.Text) != 0)
                {
                    MessageBox.Show("Old password did not match.");
                    return;
                }
            }

            if (txb_new_password.Text == "")
            {
                MessageBox.Show("Please enter new password");
                return;
            }


            if (txb_new_password.Text != txb_confirmPassword.Text)
            {
                MessageBox.Show("Password and Confirm Password did not match.");
                return;
            }

            Functions.SqlNonQuery("update " +
                                  Program.ModName_lcns + "_users set password = '******' ");
        }
Example #2
0
        void Btn_SaveClick(object sender, EventArgs e)
        {
            //check if user id already exists?
            DataTable tempDT = Functions.GetTable("select * from " + Program.ModName_lcns + "_users where name = '" + Functions.RemoveSpecial(txb_userID.Text) + "' " +
                                                  "and id <> '" + user_id + "'");

            if (tempDT.Rows.Count > 0)
            {
                MessageBox.Show("This User Name / ID already exists. Please change User ID / Name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (user_id == "" && txb_password.Text == "")
            {
                // Password should not be empty when creating new user

                MessageBox.Show("Please enter password for new user.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txb_password.Text != txb_confirmPassword.Text)
            {
                MessageBox.Show("Password and Confirm Password do not match", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txb_userID.Text == "")
            {
                MessageBox.Show("Please enter Name for new user.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (user_id == "")
            {
                //Enter new user in table
                Functions.SqlNonQuery(

                    string.Format("insert into  " + Program.ModName_lcns + "_users " +
                                  "(name, password, is_admin) values " +
                                  "('{0}', '{1}', '{2}')",

                                  Functions.RemoveSpecial(txb_userID.Text),
                                  StringCipher.Encrypt(txb_password.Text, Program.EncryptionKey),
                                  ckb_adminUser.Checked ? "1" : "0"

                                  ));

                string id = Functions.GetTable("select last_insert_id() as 'id';").Rows[0]["id"].ToString();

                //Insert new permissions
                foreach (DataGridViewRow r in dgv_rights.Rows)
                {
                    if (!DBNull.Value.Equals(r.Cells["Access"].Value) && (bool)r.Cells["Access"].Value == true)
                    {
                        Functions.SqlNonQuery(

                            string.Format("insert into  " + Program.ModName_lcns + "_user_permissions " +
                                          "(user_id, permission_group, permission) values " +
                                          "('{0}', '{1}', '{2}')",

                                          id,
                                          r.Cells["Permission Group"].Value.ToString(),
                                          r.Cells["Permission"].Value.ToString()

                                          ));
                    }
                }
            }
            else                //update existing user
            {
                Functions.SqlNonQuery(

                    string.Format("update " + Program.ModName_lcns + "_users " +
                                  "set name = '{0}', is_admin = '{1}' " +
                                  "where id = '{2}' ",

                                  Functions.RemoveSpecial(txb_userID.Text),
                                  ckb_adminUser.Checked ? "1" : "0",
                                  user_id

                                  ));

                if (txb_password.Text != "")
                {
                    //password update query

                    Functions.SqlNonQuery(

                        string.Format("update " + Program.ModName_lcns + "_users " +
                                      "set password = '******' " +
                                      "where id = '{1}' ",

                                      StringCipher.Encrypt(txb_password.Text, Program.EncryptionKey),
                                      user_id

                                      ));
                }

                Functions.SqlNonQuery(" delete from  " + Program.ModName_lcns + "_user_permissions where user_id = '" + user_id + "' ");

                //Insert new permissions
                foreach (DataGridViewRow r in dgv_rights.Rows)
                {
                    if (!DBNull.Value.Equals(r.Cells["Access"].Value) && (bool)r.Cells["Access"].Value == true)
                    {
                        Functions.SqlNonQuery(

                            string.Format("insert into  " + Program.ModName_lcns + "_user_permissions " +
                                          "(user_id, permission_group, permission) values " +
                                          "('{0}', '{1}', '{2}')",

                                          user_id,
                                          r.Cells["Permission Group"].Value.ToString(),
                                          r.Cells["Permission"].Value.ToString()

                                          ));
                    }
                }
            }

            MessageBox.Show("Saved Successfully");

            this.Close();
        }
Example #3
0
        public void openCompany()
        {
            if (lb_databases.SelectedIndex >= 0 || Program.IsDefaultDBset == true)
            {
                MySqlConnection conn = new MySqlConnection();

                try
                {
                    string database = Program.IsDefaultDBset == true ? Program.currentDB : "GBC_" + lb_databases.SelectedItem.ToString().Replace(' ', '_');
                    string connStr  = string.Format("server={0};database={1};user={2};port={3};password={4};", Program.Server, database, Program.SqlUser, Program.Port, Program.Password);

                    Program.GlobalConn = new MySqlConnection(connStr);
                    Program.GlobalConn.Open();

                    DataTable dt = Functions.GetTable("show tables like '" +
                                                      Program.ModName_lcns + "_users'");

                    if (dt.Rows.Count == 0)
                    {
                        var dialogResult = MessageBox.Show("[" + Program.ThisModuleName + "] Module has not been configured with selected database. "
                                                           + "Do you want to configure now?\n\nIt is recommended to open Accounting Module and save backup before configuring modules.", "Module Configuration", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (dialogResult == DialogResult.Yes)
                        {
                            // module configuration code
                            ConfigureModule();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        // code to open the company i.e. check userid and password

                        dt = Functions.GetTable("select name, password from "
                                                + Program.ModName_lcns + "_users where name = '" + txb_userid.Text + "'");

                        if (dt.Rows.Count == 0)
                        {
                            MessageBox.Show("User ID or Password not correct");
                        }
                        else
                        {
                            string decryptedPassword = StringCipher.Decrypt(dt.Rows[0]["password"].ToString(), Program.EncryptionKey);
                            if (string.Compare(decryptedPassword, txb_password.Text) == 0)
                            {
                                //userid and password are correct
                                Program.currentUSER = txb_userid.Text;
                                Program.MainWindow.EnableMenues(true);

                                Program.MainWindow.Text += " - [User: "******"] ";

                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("User ID or Password not correct");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionMB emb = new ExceptionMB();
                    emb.ShowMB(ex);
                }
            }
        }
Example #4
0
        private void ConfigureModule()
        {
            try
            {
                string userID   = "";
                string password = "";

                FrmNewAdminUser fna = new FrmNewAdminUser();
                if (fna.ShowDialog() == DialogResult.OK)
                {
                    userID   = fna.userid;
                    password = StringCipher.Encrypt(fna.password, Program.EncryptionKey);
                }
                else
                {
                    return;
                }

                Functions.SqlNonQueryWithoutExHandled("CREATE TABLE if not exists `" + Program.ModName_lcns + "_users` ( " +
                                                      "`id` INT NOT NULL AUTO_INCREMENT COMMENT '', " +
                                                      "`name` VARCHAR(255) NULL COMMENT '', " +
                                                      "`password` VARCHAR(255) NULL COMMENT '', " +
                                                      "`is_admin` TINYINT NULL COMMENT '', " +
                                                      "PRIMARY KEY(`id`)  COMMENT '', " +
                                                      "UNIQUE INDEX `name_UNIQUE` (`name` ASC)  COMMENT '') engine = innodb; ",
                                                      Program.GlobalConn);

                Functions.SqlNonQueryWithoutExHandled("CREATE TABLE if not exists `" + Program.ModName_lcns + "_user_permissions` ( " +
                                                      "`id` INT NOT NULL AUTO_INCREMENT COMMENT '', " +
                                                      "`user_id` INT NOT NULL COMMENT '', " +
                                                      "`permission` VARCHAR(255) NOT NULL COMMENT '', " +
                                                      "PRIMARY KEY(`id`)  COMMENT '', " +
                                                      "INDEX `fk_" + Program.ModName_lcns + "_permissions_userid_idx` (`user_id` ASC)  COMMENT '', " +
                                                      "CONSTRAINT `fk_" + Program.ModName_lcns + "_permissions_userid` " +
                                                      "FOREIGN KEY (`user_id`) " +
                                                      "REFERENCES `" + Program.ModName_lcns + "_users` (`id`) " +
                                                      "ON DELETE CASCADE " +
                                                      "ON UPDATE CASCADE) engine = innodb; ",
                                                      Program.GlobalConn);

                Functions.SqlNonQueryWithoutExHandled("ALTER TABLE `" + Program.ModName_lcns + "_user_permissions` " +
                                                      "ADD COLUMN `permission_group` VARCHAR(255) NULL AFTER `user_id`;", Program.GlobalConn);

                Functions.SqlNonQueryWithoutExHandled("INSERT INTO `" + Program.ModName_lcns + "_users` (`name`, `password`, `is_admin`) VALUES ('" + userID + "', '" + password + "', '1')", Program.GlobalConn);

                // MODULE RELATED TABLES - START

                //Functions.SqlNonQueryWithoutExHandled("", Program.GlobalConn);

                Functions.SqlNonQueryWithoutExHandled("CREATE TABLE `" + Program.ModName_lcns + "_factor` ( " +
                                                      "`id` INT NOT NULL AUTO_INCREMENT COMMENT '', " +
                                                      "`coa_name` VARCHAR(500) NOT NULL COMMENT '', " +
                                                      "`factor` DECIMAL(40,5) NOT NULL COMMENT '', " +
                                                      "PRIMARY KEY (`id`)  COMMENT '', " +
                                                      "INDEX `fk_coa_name_idx` (`coa_name` ASC)  COMMENT '', " +
                                                      "CONSTRAINT `fk_coa_name` " +
                                                      "FOREIGN KEY (`coa_name`) " +
                                                      "REFERENCES `coa` (`Name`) " +
                                                      "ON DELETE CASCADE " +
                                                      "ON UPDATE CASCADE) engine = innodb;", Program.GlobalConn);

                Functions.SqlNonQueryWithoutExHandled("ALTER TABLE `poultry_pm_factor` " +
                                                      "ADD UNIQUE INDEX `coa_name_UNIQUE` (`coa_name` ASC);", Program.GlobalConn);



                // ENTRIES AND RECIPE TABLES SHOULD BE SAME

                Functions.SqlNonQueryWithoutExHandled("ALTER TABLE `entries` " +
                                                      "ADD COLUMN `supply_rate` DECIMAL(40,5) NULL DEFAULT NULL AFTER `Qty`, " +
                                                      "ADD COLUMN `factor` DECIMAL(20,5) NULL DEFAULT NULL AFTER `supply_rate`;", Program.GlobalConn);

                Functions.SqlNonQueryWithoutExHandled("ALTER TABLE `recipes` " +
                                                      "ADD COLUMN `supply_rate` DECIMAL(40,5) NULL DEFAULT NULL AFTER `Qty`, " +
                                                      "ADD COLUMN `factor` DECIMAL(20,5) NULL DEFAULT NULL AFTER `supply_rate`;", Program.GlobalConn);

                // ENTRIES AND RECIPE TABLES SHOULD BE SAME


                MessageBox.Show("Module configured successfully.", "Module Configuration", MessageBoxButtons.OK, MessageBoxIcon.Information);
                // MODULE RELATED TABLES - END
            }
            catch (Exception ex)
            {
                ExceptionMB emb = new ExceptionMB();
                emb.ShowMB(ex);
            }
            finally
            {
            }
        }