예제 #1
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;
            }
        }
예제 #2
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.";
            }
        }
예제 #3
0
 public void Add(Category category)
 {
     try
     {
         //insert category name to db
         string insert = "INSERT INTO Categories VALUES('" + category.Name + "')";
         _common.QueryOperation(insert, connection);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
         connection.Close();
     }
 }
예제 #4
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                stockIn.CompanyId  = Convert.ToInt32(companyComboBox.SelectedValue);
                stockIn.CategoryId = Convert.ToInt32(categoryComboBox.SelectedValue);
                stockIn.ItemId     = Convert.ToInt32(itemComboBox.SelectedValue);
                stockIn.Quantity   = Convert.ToInt32(avialableQuantityTextBox.Text);
                stockIn.Quantity  += Convert.ToInt32(stockInQuantityTextBox.Text);


                string insert  = @"IF EXISTS(select* from stockin where itemid=" + stockIn.ItemId + ") update stockin set quantity = " + stockIn.Quantity + ", categoryId='" + stockIn.CategoryId + "',CompanyId='" + stockIn.CompanyId + "' where itemid = " + stockIn.ItemId + " ELSE insert into stockin values(" + stockIn.CategoryId + "," + stockIn.ItemId + ", " + stockIn.Quantity + ", " + stockIn.CompanyId + ")";
                bool   isAdded = _common.QueryOperation(insert, connection);
                if (isAdded)
                {
                    MessageBox.Show("Stock in successfully!!");
                    avialableQuantityTextBox.Text = stockIn.Quantity.ToString();
                    stockInQuantityTextBox.Clear();
                }
                else
                {
                    MessageBox.Show("Something is WRONG!");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Something is WRONG!");
            }
        }
예제 #5
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;
     }
 }
예제 #6
0
 private void sellButton_Click(object sender, EventArgs e)
 {
     foreach (StockOut stockOut in stockOutList)
     {
         string stockoutQuery = "INSERT INTO stockout Values('" + stockOut.CompanyName + "','" + stockOut.CategoryName + "','" + stockOut.ItemName + "','" + stockOut.OutQuantity + "','" + stockOut.Date + "','" + (StockOutType.Sold) + "')";
         _common.QueryOperation(stockoutQuery, connection);
         string UpdateStock = "UPDATE stockin SET quantity=" + stockOut.Quantity + " where itemId=" + stockOut.ItemId + "";
         _common.QueryOperation(UpdateStock, connection);
     }
     MessageBox.Show("Item Sold!");
     stockOutDataGridView.DataSource = null;
     stockOutList.Clear();
 }