Пример #1
0
        public bool IsExist(Category category)
        {
            string search = "SELECT * FROM Categories WHERE Name=('" + category.Name + "')";
            bool   result = _common.Reader(connection, search);

            return(result);
        }
Пример #2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            User user = new User();


            if (adminRadioButton.Checked)
            {
                user.userType = 1;
            }

            else if (userRadioButton.Checked)
            {
                user.userType = 2;
            }

            if (userNameSetTextBox.Text != "" && passwordSetTextBox.Text != "" && RadioButtonValidation() == true)
            {
                user.userName = userNameSetTextBox.Text;
                user.PassWord = passwordSetTextBox.Text;

                try
                {
                    //search for same category
                    string search = "SELECT * FROM Users WHERE UserName='******' AND PassWord='******' ";
                    bool   result = _common.Reader(connection, search);
                    if (result == true)
                    {
                        warningLabel.Text = "User already Exist!";
                        return;
                    }
                    else
                    {
                        //insert
                        string userAddQuery = @"INSERT INTO Users VALUES('" + user.userName + "', '" + user.PassWord + "', '" + user.userType + "')";
                        _common.QueryOperation(userAddQuery, connection);

                        MessageBox.Show("Added Successfully!!");

                        userNameSetTextBox.ResetText();
                        passwordSetTextBox.ResetText();
                    }
                    //Update Function
                    string fetch = "SELECT * FROM Users ORDER BY Id DESC";
                    _common.FillGrid(fetch, connection, userGridView);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    throw;
                }
            }
            else
            {
                MessageBox.Show("Please Fill properly!!");
                return;
            }
        }
Пример #3
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (itemTextBox.Text.Length > 2)
            {
                try
                {
                    _item.CategoryId   = Convert.ToInt32(categoryComboBox.SelectedValue);
                    _item.CompanyId    = Convert.ToInt32(companyComboBox.SelectedValue);
                    _item.Name         = itemTextBox.Text;
                    _item.ReorderLevel = Convert.ToInt32(reorderLevelTextBox.Text);

                    //search for same category
                    string search = "SELECT * FROM items WHERE Name=('" + _item.Name + "')";

                    bool result = _common.Reader(connection, search);

                    if (result == true)
                    {
                        warningLabel.Text = "Item already Exist!";
                        return;
                    }
                    else
                    {
                        string insert = @"INSERT INTO items VALUES('" + _item.Name + "','" + _item.ReorderLevel + "','" + _item.CategoryId + "','" + _item.CompanyId + "')";


                        bool isAdded = _common.QueryOperation(insert, connection);
                        if (isAdded)
                        {
                            MessageBox.Show("Item Added");
                            companyComboBox.ResetText();
                            categoryComboBox.ResetText();
                            itemTextBox.Clear();
                            reorderLevelTextBox.Clear();
                            string insert3 = @"SELECT TOP 1 * FROM items ORDER BY id DESC";

                            connection.Open();
                            SqlCommand command1 = new SqlCommand(insert3, connection);
                            int        itemId   = Convert.ToInt32(command1.ExecuteScalar());
                            connection.Close();
                            string insert2 = @"INSERT INTO stockin VALUES('" + _item.CategoryId + "','" + itemId + "',0,'" + _item.CompanyId + "')";
                            _common.QueryOperation(insert2, connection);
                        }
                    }
                }
                catch (Exception exception)
                {
                    connection.Close();
                    MessageBox.Show(exception.Message);
                }
            }
            else
            {
                warningLabel.Text = "Name at least 3 characters.";
            }
        }
Пример #4
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     if (nameTextBox.Text.Length > 2)
     {
         try
         {
             _company.Name = nameTextBox.Text;
             //search for same category
             string search = "SELECT * FROM Companies WHERE Name=('" + _company.Name + "')";
             bool   result = _common.Reader(connection, search);
             if (result == true)
             {
                 warningLabel.Text = "Category already Exist!";
                 return;
             }
             else
             {
                 //insert category name to db
                 string insert  = "INSERT INTO Companies VALUES('" + _company.Name + "')";
                 bool   isAdded = _common.QueryOperation(insert, connection);
                 if (!isAdded)
                 {
                     return;
                 }
                 nameTextBox.Clear();
                 MessageBox.Show("Added Succesfully!");
                 CompanyForm_Load(this, null);
             }
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.Message);
         }
     }
     else
     {
         warningLabel.Text = "Name at least 3 character!";
         return;
     }
 }