private void buttonExport_Click(object sender, EventArgs e) { string pathCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + textBoxPath.Text + "; Extended Properties=\"Excel 8.0;HDR=Yes\";"; OleDbConnection conn = new OleDbConnection(pathCon); OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from [EntrySheet$]", conn); DataTable dt = new DataTable(); adapter.Fill(dt); Insertion insert = new Insertion(); foreach (DataRow row in dt.Rows) { DataTable dtcategoryId = retrieve.GetId("usp_GetCategoryId", row[5].ToString()); insert.SaveProductDetails(row[0].ToString(), row[1].ToString(), Convert.ToDecimal(row[2]), row[3].ToString(), Convert.ToDecimal(row[4]), Convert.ToInt32(dtcategoryId.Rows[0][0].ToString()), Convert.ToDecimal(row[5])); } retrieve.ShowProducts(dataGridViewProduct, ProductIdGv, ProductNameGv, ProductCodeGv, ProductPriceGv, ProductUnitGv, ProductMinValGv, ProductCatNameGv, ProductCatIdGv, SalesPriceGv); }
public override void buttonSave_Click(object sender, EventArgs e) { if (textBoxProductName.Text == "") { labelProductNameError.Visible = true; } else { labelProductNameError.Visible = false; } if (textBoxProductCode.Text == "") { labelProductCodeError.Visible = true; } else { labelProductCodeError.Visible = false; } if (textBoxPrice.Text == "") { labelPurchasePriceError.Visible = true; } else { labelPurchasePriceError.Visible = false; } if (textBoxUnit.Text == "") { labelUnitError.Visible = true; } else { labelUnitError.Visible = false; } if (textBoxMinimumValue.Text == "") { labelMinValueError.Visible = true; } else { labelMinValueError.Visible = false; } if (textBoxSalesPrice.Text == "") { labelSalePriceError.Visible = true; } else { labelSalePriceError.Visible = false; } if (comboBoxCategory.SelectedIndex == -1) { labelCategoryError.Visible = true; } else { labelCategoryError.Visible = false; } if (labelProductNameError.Visible || labelProductCodeError.Visible || labelPurchasePriceError.Visible || labelUnitError.Visible || labelMinValueError.Visible || labelCategoryError.Visible || labelSalePriceError.Visible) { MainClass.ShowMessage("Fields with * are mandatory", "Error", "Error"); //Error is the type of message. } else { if (edit == 0) //Code for save operation { Insertion insert = new Insertion(); insert.SaveProductDetails(textBoxProductName.Text, textBoxProductCode.Text, Convert.ToDecimal(textBoxPrice.Text), textBoxUnit.Text, Convert.ToDecimal(textBoxMinimumValue.Text), Convert.ToInt32(comboBoxCategory.SelectedValue), Convert.ToDecimal(textBoxSalesPrice.Text), true); retrieve.ShowProducts(dataGridViewProduct, ProductIdGv, ProductNameGv, ProductCodeGv, ProductPriceGv, ProductUnitGv, ProductMinValGv, ProductCatNameGv, ProductCatIdGv, SalesPriceGv); //MainClass.Disable_Reset(panelRightSlider); } else if (edit == 1) //code for update operaiton { DialogResult dr = MessageBox.Show("Are you sure, you want to update record.", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { Updation update = new Updation(); update.UpdateProductDetails(textBoxProductName.Text, textBoxProductCode.Text, Convert.ToDecimal(textBoxPrice.Text), textBoxUnit.Text, Convert.ToDecimal(textBoxMinimumValue.Text), CategoryId, ProductId, Convert.ToDecimal(textBoxSalesPrice.Text)); retrieve.ShowProducts(dataGridViewProduct, ProductIdGv, ProductNameGv, ProductCodeGv, ProductPriceGv, ProductUnitGv, ProductMinValGv, ProductCatNameGv, ProductCatIdGv, SalesPriceGv); // MainClass.Disable_Reset(panelRightSlider); } } } }