예제 #1
0
 private void GetSQLConnection(SQLServerConnect sqlconnection)
 {
     this.serverConn = sqlconnection;
     if (Roles.DataBaseRole == DataBaseRole.User)
     {
         AdminButton.Visible   = false;
         ManagerButton.Visible = false;
         UserButton.Visible    = true;
         CartButton.Visible    = false;
     }
     else if (Roles.DataBaseRole == DataBaseRole.Admin)
     {
         AdminButton.Visible   = true;
         ManagerButton.Visible = true;
         UserButton.Visible    = false;
         CartButton.Visible    = false;
     }
     else
     {
         AdminButton.Visible   = false;
         ManagerButton.Visible = true;
         UserButton.Visible    = false;
         CartButton.Visible    = false;
     }
 }
예제 #2
0
        private void RegistationButton_Click(object sender, EventArgs e)
        {
            ClientInfo    c_info        = new ClientInfo(name_textbox.Text, lname_textbox.Text, phone_textbox.Text, address_textbox.Text);
            Authorization authorization = new Authorization(login_text_box.Text, password_textbox.Text);

            SQLServerConnect.CreateNewClientAndUser(authorization, c_info);
            this.Close();
        }
예제 #3
0
        public static void СreateNewEntry(SQLServerConnect servConn, GroupBox gb, string tableName, int attributesCount)
        {
            string[] values     = new string[attributesCount];
            string[] attributes = new string[attributesCount];

            int i = 0;

            foreach (TextBox tb in gb.Controls.Cast <Control>().Where(x => x is TextBox).Select(x => x as TextBox))
            {
                values[i]     = tb.Text;
                attributes[i] = tb.Tag.ToString();
                i++;
            }
            servConn.InsertInto(tableName, values, attributes);
        }
예제 #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                authorization = new Authorization(txbx_login.Text, txbx_password.Text);
                serverConn    = new SQLServerConnect(@"DESKTOP-0PMHTR5", "FruitVegetablesShop", $"{authorization.Login}", $"{authorization.Password}");

                if (!serverConn.OpenSqlConnection())
                {
                    MessageBox.Show("Unable to login, you entered an incorrect username or password");
                    return;
                }
                SetRole(authorization.Login);
                SQLConnectionEvent?.Invoke(serverConn);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #5
0
        public static void FillDataGridView(SQLServerConnect servConn, DataGridView dgw, string tableName)
        {
            dgw.Rows.Clear();
            dgw.Columns.Clear();

            int  count  = servConn.CountRows(tableName);
            bool create = true;
            var  reader = servConn.SelectAll(tableName);

            if (count == 0)
            {
                for (var k = 0; k < reader.FieldCount; k++)
                {
                    dgw.Columns.Add(reader.GetName(k), reader.GetName(k));
                }
            }

            for (var i = 0; i < count; i++)
            {
                reader.Read();
                if (create)
                {
                    for (var k = 0; k < reader.FieldCount; k++)
                    {
                        dgw.Columns.Add(reader.GetName(k), reader.GetName(k));
                    }
                    create = false;
                }
                dgw.Rows.Add();
                for (var j = 0; j < reader.FieldCount; j++)
                {
                    dgw.Rows[i].Cells[j].Value  = reader.GetValue(j);
                    dgw.Columns[j].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
            }
        }
예제 #6
0
 public Buy(SQLServerConnect connect)
 {
     servConn = connect;
     InitializeComponent();
 }
예제 #7
0
        public static void UpdateField(SQLServerConnect servConn, GroupBox gb, string tableName, int attributesCount)
        {
            try
            {
                TextBox  txtbx_id   = new TextBox();
                string[] values     = new string[attributesCount];
                string[] attributes = new string[attributesCount];
                string   id         = "prod_id"; //1
                if (tableName == "FV_Order")     //2
                {
                    id = "order_id";
                }
                if (tableName == "FV_Customer")//3
                {
                    id = "cust_login";
                }
                if (tableName == "FV_Delivery")//4
                {
                    id = "del_id";
                }
                if (tableName == "FV_Employee" || tableName == "FV_EmployeeInfo")//5 6
                {
                    id = "emp_id";
                }
                if (tableName == "FV_Stock")//7
                {
                    id = "stock_id";
                }
                if (tableName == "FV_Post")//8
                {
                    id = "post_id";
                }
                if (tableName == "FV_Provide")//9
                {
                    id = "prov_id";
                }
                if (tableName == "FV_Provider")//10
                {
                    id = "provider_id";
                }


                int i = 0;
                foreach (TextBox tb in gb.Controls.Cast <Control>().Where(x => x is TextBox).Select(x => x as TextBox))
                {
                    if (tb.Tag.ToString().ToLower() == id)
                    {
                        txtbx_id = tb;
                    }
                    else
                    {
                        values[i]     = tb.Text;
                        attributes[i] = tb.Tag.ToString();

                        i++;
                    }
                }

                servConn.UpdateField(tableName, txtbx_id.Tag.ToString(), txtbx_id.Text, values, attributes);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #8
0
 public static void DeleteField(SQLServerConnect servConn, string tableName, TextBox txtbx)
 {
     servConn.Delete(tableName, txtbx.Tag.ToString(), txtbx.Text);
 }
예제 #9
0
 public Statistic(SQLServerConnect conn)
 {
     InitializeComponent();
     servConn = conn;
 }