private void BtAct_Click(object sender, EventArgs e) { int Code; string Name; double Price; int Amount; if (tbCode.ReadOnly == true) { tbCode.ReadOnly = false; tbType.ReadOnly = false; tbName.ReadOnly = false; tbPrice.ReadOnly = false; tbAmount.ReadOnly = false; btAct.Text = "Изменить"; } else if (Int32.TryParse(tbCode.Text, out Code) && tbName.Text != "" && Double.TryParse(tbPrice.Text, out Price) && Int32.TryParse(tbAmount.Text, out Amount)) { SAcs Acs = new SAcs(EnumAcs.None); Acs.TryStringToAcs(tbType.Text); Name = tbName.Text; Prod = new Product(Code, Acs, Name, Price, Amount); IsCancel = false; this.Close(); } else { MessageBox.Show("Ошибка", "Вы ввели некорректные данные, повторите ввод.", MessageBoxButtons.OK); } }
public bool XMLFileToProductList(string path) { XmlDocument doc = new XmlDocument(); doc.Load(path); if (doc.DocumentElement.LocalName == "ProductList") { foreach (XmlElement elem in doc.DocumentElement.ChildNodes) { Product prod = null; try { int Code = Convert.ToInt32(elem.ChildNodes[0].InnerText); SAcs Acs = new SAcs(); Acs.TryStringToAcs(elem.ChildNodes[1].InnerText); //MessageBox.Show(elem.ChildNodes[1].InnerText); string Name = elem.ChildNodes[2].InnerText; if (Name == "") { continue; } double Price = Convert.ToDouble(elem.ChildNodes[3].InnerText); int Amount = Convert.ToInt32(elem.ChildNodes[4].InnerText); prod = new Product(Code, Acs, Name, Price, Amount); } catch { continue; } this.Add(prod); } } return(true); }
private static Product GetProductFromFile(StreamReader sr) { bool OK = !sr.EndOfStream; string StrCode = ""; string StrAcs = ""; string StrName = ""; string StrPrice = ""; string StrAmount = ""; OK = GetValueFromFile(sr, out StrCode) && GetValueFromFile(sr, out StrAcs) && GetValueFromFile(sr, out StrName) && GetValueFromFile(sr, out StrPrice) && GetValueFromFile(sr, out StrAmount); sr.ReadLine(); if (OK) { int Code = 0; SAcs Acs = new SAcs(); double Price = 0; int Amount = 0; if (OK && Int32.TryParse(StrCode, out Code) && Double.TryParse(StrPrice, out Price) && Int32.TryParse(StrAmount, out Amount) && StrName != "") { Acs.TryStringToAcs(StrAcs); Product prod = new Product(Code, Acs, StrName, Price, Amount); return(prod); } } return(null); }
public Product(int ACode = 0, SAcs AKind = new SAcs(), string AName = "", double APrice = 0, int AAmount = 0) { code = ACode; kind.Acs = AKind.Acs; name = AName; price = APrice; amount = AAmount; }
private void TSEditRandom_Click(object sender, EventArgs e) { using (InputForm form = new InputForm("Ввод", "Введите количество рандомных товаров: ")) { form.ShowDialog(); int k; if (!form.isCancel && Int32.TryParse(form.Info, out k)) { if (IsModified) { if (SaveModified() == DialogResult.Cancel) { return; } } ProdList.Clear(); for (int i = 0; i < k; i++) { int Code = rand.Next(1, 1001 + k); while (i > 0 && ProdList.Exists(x => x.Code == Code)) { Code = rand.Next(1, 1001 + k); } ; SAcs Acs = new SAcs((EnumAcs)rand.Next(1, 12)); string Name = Acs.ToString() + Convert.ToString(i + 1); double Price = rand.NextDouble() * 10000; int Amount = rand.Next(0, 2001); Product prod = new Product(Code, Acs, Name, Price, Amount); ProdList.Add(prod); } ProdList.ProductListToDGV(dgvFile); } } }