private void UpdateProduct() { if (datagrid_storage.DataSource != null) { FillForm fill = new FillForm( ); Product foo; int rowindex = 0; #region Setup product ArrayList a = new ArrayList( ); if (datagrid_storage.SelectedCells.Count > 0) { rowindex = datagrid_storage.SelectedCells[0].RowIndex; DataGridViewRow drow = datagrid_storage.Rows[rowindex]; foreach (DataGridViewCell item in drow.Cells) { a.Add(item); } } // TODO int id = int.Parse(((DataGridViewCell)a[0]).Value.ToString( )), quantity = int.Parse(((DataGridViewCell)a[1]).Value.ToString( )); float price = float.Parse(((DataGridViewCell)a[3]).Value.ToString( )); string lable = ((DataGridViewCell)a[2]).Value.ToString( ), volume = ((DataGridViewCell)a[4]).Value.ToString( ), type = ((DataGridViewCell)a[5]).Value.ToString( ); foo = new Product(id, volume, type, lable, quantity, price); #endregion fill.UpdateProduct(foo); fill.ShowDialog( ); if (!fill.IsDisposed) { foreach (Product item in Product.List) { if (item.Id == id) { Product bar = fill.NewProduct(id); int qu = item.Quantity >= fill.Quantity ? (item.Quantity - fill.Quantity) : fill.Quantity; bar.Storage.ComingStorage(bar, qu, Store.ListType.IN); item.UpdateXML(bar); break; } } fill.Dispose( ); fill.Close( ); RefreshForm( ); datagrid_storage.Rows[0].Selected = false; datagrid_storage.Rows[rowindex].Selected = true; } } }
private void NewProduct() { FillForm fill = new FillForm( ); Product fooprod; fill.ShowDialog( ); if (!fill.IsDisposed) { if ((fooprod = fill.NewProduct(Product.GenerateID( ))) != null) { fooprod.AddXML( ); fooprod.Storage.ComingStorage(fooprod, fill.Quantity, Store.ListType.IN); #region Generate Rest XElement Xrest = new XElement("rest", new XAttribute("date", DateTime.Today.ToShortDateString( )), new XElement("product", new XElement("id", fooprod.Id.ToString( )), new XElement("quantity", fooprod.Quantity.ToString( )))); if (!(Store.XSource == null)) { int index = (int)XFile.FileType.IO; Store.XSource.SetDocument(XFile.Paths[index]); } if (!(Store.XSource.Exists)) { MessageBox.Show("No Document was set"); Store.XSource.OpenDocument(XFile.FileType.IO); } Store.XSource.XML_File.Root.Add(Xrest); Store.XSource.XML_File.Save(Store.XSource.Xmlpath); #endregion fill.Dispose( ); fill.Close( ); if (!is_shown) { ShowHide( ); } RefreshForm( ); foreach (DataGridViewRow row in datagrid_storage.Rows) { row.Selected = false; } datagrid_storage.Rows[datagrid_storage.Rows.Count - 1].Selected = true; } } }