public AddNewProduct(int iProductID) { InitializeComponent(); ProductID = iProductID; IsUpdateMode = true; InventoryStoreDataSet.tblProductsDataTable dt = taProducts.GetProductByID(ProductID); if (dt.Rows.Count > 0) { trProductsRow = dt.Rows[0] as InventoryStoreDataSet.tblProductsRow; } }
private void btnImportStock_Click(object sender, EventArgs e) { string connString = "Dsn=SageLine50v10;uid=manager;Pwd=eplslrc;"; OdbcConnection conn = new OdbcConnection(connString); OdbcCommand comm = new OdbcCommand(); comm.Connection = conn; comm.CommandTimeout = 300; comm.CommandText = "SELECT STOCK_CODE AS ProductName, DESCRIPTION, WEB_DESCRIPTION AS ProductTag1, WEB_DETAILS, WEB_CATEGORY_1, SALES_PRICE, 1 AS Discontinued FROM STOCK"; conn.Open(); OdbcDataAdapter da = new OdbcDataAdapter(comm); DataSet ds = new DataSet(); da.Fill(ds); //var prds = this.inventoryStoreDataSet.tblProducts; //prds.Merge(ds.Tables[0],true); InventoryStoreDataSetTableAdapters.tblProductsTableAdapter taProducts = new InventoryStoreDataSetTableAdapters.tblProductsTableAdapter(); InventoryStoreDataSet.tblProductsRow trProductsRow; foreach (DataRow dr in ds.Tables[0].Rows) { trProductsRow = dr as InventoryStoreDataSet.tblProductsRow; InventoryStoreDataSet.tblProductsDataTable dt = taProducts.GetProductByID(ProductID); if (dt.Rows.Count > 0) { trProductsRow = dt.Rows[0] as InventoryStoreDataSet.tblProductsRow; } if (taProducts.Update(trProductsRow) > 0) { //MessageBox.Show("Product updated successfully", "Product Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); //return true; } else { taProducts.Insert(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), decimal.Parse(dr[5].ToString()), false); } } this.tblProductsTableAdapter.FillActiveProducts(this.inventoryStoreDataSet.tblProducts); }
static public void FillProducts(ComboBox cmbProducts, bool IsSelectRowRequired, string strSelectRowText) { InventoryStoreDataSet.tblProductsDataTable dt = new InventoryStoreDataSet.tblProductsDataTable(); InventoryStoreDataSetTableAdapters.tblProductsTableAdapter adp = new InventoryStoreDataSetTableAdapters.tblProductsTableAdapter(); adp.FillActiveProducts(dt); if (IsSelectRowRequired) { InventoryStoreDataSet.tblProductsRow dr1 = dt.NewtblProductsRow(); dr1.ProductID = 0; dr1.ProductName = strSelectRowText; dr1.Manufacturer = ""; dr1.ProductTag1 = ""; dr1.ProductTag2 = ""; dr1.Discontinued = true; dt.Rows.InsertAt(dr1, 0); } cmbProducts.DataSource = dt; cmbProducts.DisplayMember = "ProductName"; cmbProducts.ValueMember = "ProductID"; // Enable the owner draw on the ComboBox. cmbProducts.DrawMode = DrawMode.OwnerDrawFixed; // Handle the DrawItem event to draw the items. cmbProducts.DrawItem += delegate(object comboBox, DrawItemEventArgs args) { // Draw the default background args.DrawBackground(); // The ComboBox is bound to a DataTable, // so the items are DataRowView objects. InventoryStoreDataSet.tblProductsRow drv = (InventoryStoreDataSet.tblProductsRow)(((DataRowView)cmbProducts.Items[args.Index]).Row); // Retrieve the value of each column. string productName = drv.ProductName; string manufacturer = (drv.Manufacturer == null) ? "" : drv.Manufacturer; string productTag1 = drv.ProductTag1 == null ? "" : drv.ProductTag1; string productTag2 = drv.ProductTag2 == null ? "" : drv.ProductTag2; // Get the bounds for the first column Rectangle r1 = args.Bounds; r1.Width /= 4; // Draw the text on the first column using (SolidBrush sb = new SolidBrush(args.ForeColor)) { args.Graphics.DrawString(productName, args.Font, sb, r1); } // Draw a line to isolate the columns using (Pen p = new Pen(Color.Black)) { args.Graphics.DrawLine(p, r1.Right, 0, r1.Right, r1.Bottom); } // Get the bounds for the second column Rectangle r2 = args.Bounds; r2.X = r1.Right; r2.Width /= 4; // Draw the text on the second column using (SolidBrush sb = new SolidBrush(args.ForeColor)) { args.Graphics.DrawString(manufacturer, args.Font, sb, r2); } // Draw a line to isolate the columns using (Pen p = new Pen(Color.Black)) { args.Graphics.DrawLine(p, r2.Right, 0, r2.Right, r2.Bottom); } // Get the bounds for the second column Rectangle r3 = args.Bounds; r3.X = r2.Right; r3.Width /= 4; // Draw the text on the second column using (SolidBrush sb = new SolidBrush(args.ForeColor)) { args.Graphics.DrawString(productTag1, args.Font, sb, r3); } // Draw a line to isolate the columns using (Pen p = new Pen(Color.Black)) { args.Graphics.DrawLine(p, r3.Right, 0, r3.Right, r3.Bottom); } // Get the bounds for the second column Rectangle r4 = args.Bounds; r4.X = r3.Right; r4.Width /= 4; // Draw the text on the second column using (SolidBrush sb = new SolidBrush(args.ForeColor)) { args.Graphics.DrawString(productTag2, args.Font, sb, r4); } }; }