Esempio n. 1
0
        private void btnManageProduct_Click(object sender, EventArgs e)
        {
            frmProductList productList = new frmProductList();

            productList.TopLevel = false;
            panelContainer.Controls.Add(productList);
            productList.BringToFront();
            productList.LoadRecords();
            productList.Show();
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(DBConnection.MyConnection()))
                {
                    string brandid = "", categoryid = "";

                    SqlCommand    sqlCommand;
                    SqlDataReader sqlDataReader;

                    #region Select BrandId
                    string BQuery = @"select id from tblBrand where brand like @brand";
                    sqlConnection.Open();
                    sqlCommand = new SqlCommand(BQuery, sqlConnection);
                    sqlCommand.Parameters.AddWithValue("@brand", SqlDbType.VarChar).Value = cmbBrand.Text;
                    sqlDataReader = sqlCommand.ExecuteReader();
                    sqlDataReader.Read();
                    if (sqlDataReader.HasRows)
                    {
                        brandid = sqlDataReader[0].ToString();
                    }
                    sqlConnection.Close();
                    sqlDataReader.Close();
                    #endregion

                    #region Select CategoryId
                    string CQuery = @"select id from tblcategory where category like @category";
                    sqlConnection.Open();
                    sqlCommand = new SqlCommand(CQuery, sqlConnection);
                    sqlCommand.Parameters.AddWithValue("@category", SqlDbType.VarChar).Value = cmbCategory.Text;
                    sqlDataReader = sqlCommand.ExecuteReader();
                    sqlDataReader.Read();
                    if (sqlDataReader.HasRows)
                    {
                        categoryid = sqlDataReader[0].ToString();
                    }
                    sqlConnection.Close();
                    sqlDataReader.Close();
                    #endregion

                    #region Insert Product
                    string PQuery = @"insert into tblProduct (pcode,barcode,pdesc,brandid,categoryid,price) values (@pcode,@barcode,@pdesc,@brandid,@categoryid,@price)";
                    sqlConnection.Open();
                    sqlCommand = new SqlCommand(PQuery, sqlConnection);
                    sqlCommand.Parameters.AddWithValue("@pcode", txtProductCode.Text);
                    sqlCommand.Parameters.AddWithValue("@barcode", txtBarcode.Text);
                    sqlCommand.Parameters.AddWithValue("@pdesc", txtDescription.Text);

                    if (string.IsNullOrEmpty(brandid))
                    {
                        brandid = "0";
                    }
                    sqlCommand.Parameters.AddWithValue("@brandid", int.Parse(brandid));

                    if (string.IsNullOrEmpty(categoryid))
                    {
                        categoryid = "0";
                    }
                    sqlCommand.Parameters.AddWithValue("@categoryid", int.Parse(categoryid));

                    if (string.IsNullOrEmpty(txtPrice.Text.Trim()))
                    {
                        txtPrice.Text = "0";
                    }
                    sqlCommand.Parameters.AddWithValue("@price", decimal.Parse(txtPrice.Text.Trim()));


                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    #endregion

                    MessageBox.Show("Product has been successfully saved.", _msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Clear();
                    _frmProductList.LoadRecords();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), _msg, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }