private void btn_add_Click(object sender, EventArgs e) { bool error = false; try { type = comboBox1.SelectedItem.ToString(); type = type.Substring(0, type.IndexOf('-')); } catch { MessageBox.Show("نوع کالا را انتخاب کنید"); error = true; } if (!error) { try { codeTaminKonande = comboBox2.SelectedItem.ToString(); codeTaminKonande = codeTaminKonande.Substring(0, codeTaminKonande.IndexOf('-')); } catch { MessageBox.Show("تأمین کننده را انتخاب کنید"); error = true; } } try { long test; if (txt_bedehkar.Text == "" || txt_bedehkar.Text == null) { txt_bedehkar.Text = "0"; } if (txt_bestankar.Text == "" || txt_bestankar.Text == null) { txt_bestankar.Text = "0"; } test = long.Parse(txt_bedehkar.Text); test = long.Parse(txt_bestankar.Text); } catch { MessageBox.Show("مبلغ بدهکار و بستانکار را درست وارد کنید"); error = true; } if (!error && (txt_name.Text == "" || txt_price.Text == "")) { MessageBox.Show("فیلد ها را پر کنید"); error = true; } if (!error) { try { long test; if (txt_tedad.Text == "") { txt_tedad.Text = "0"; } test = long.Parse(txt_tedad.Text); } catch { MessageBox.Show("تعداد را درست وارد کنید"); error = true; } } if (!error) { serial = txt_factor.Text; name = txt_name.Text; tarikhSakht = txt_tarikhSakht.Text; tarikhEngheza = txt_tarikhEngheza.Text; price = txt_price.Text; tedad = txt_tedad.Text; tozihat = txt_tozihat.Text; bedehkar = txt_bedehkar.Text; bestankar = txt_bestankar.Text; tarikh = txt_tarikh.Text; vazeiat = "قیمت گذاری نشده"; sabteKala = new SabteKala(); sabteKala.add(serial, name, type, tarikhSakht, tarikhEngheza, price, tedad, bedehkar, bestankar, tozihat, codeTaminKonande, tarikh, vazeiat); showData(); txt_name.Text = ""; txt_tarikhSakht.Text = ""; txt_tarikhEngheza.Text = ""; txt_price.Text = ""; txt_tozihat.Text = ""; txt_tedad.Text = ""; txt_bedehkar.Text = ""; txt_bestankar.Text = ""; txt_tarikh.Text = ""; txt_factor.Text = ""; } }
private void btn_add_Click(object sender, EventArgs e) { int count = dataGridView1.SelectedRows.Count; if (count != 0) { bool error = false; try { long test; test = long.Parse(textBox1.Text); } catch { MessageBox.Show("قیمت را درست وارد کنید"); error = true; } if (!error && (textBox1.Text == "")) { MessageBox.Show("قیمت فروش وارد نشده"); error = true; } //if (!error) //{ // long buyPrice = long.Parse(txt_price.Text); // long sellPrice = long.Parse(textBox1.Text); // if (buyPrice >= sellPrice) MessageBox.Show("قیمت فروش کمتر از قیمت خرید است"); //} if (!error) { id = Int32.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()); serial = txt_factor.Text; name = txt_name.Text; type = comboBox1.SelectedItem.ToString(); type = type.Substring(0, type.IndexOf('-')); tarikhSakht = txt_tarikhSakht.Text; tarikhEngheza = txt_tarikhEngheza.Text; price = txt_price.Text; tedad = txt_tedad.Text; tozihat = txt_tozihat.Text; bedehkar = txt_bedehkar.Text; bestankar = txt_bestankar.Text; tarikh = txt_tarikh.Text; vazeiat = "قیمت گذاری نشده"; sabteKala = new SabteKala(); sabteKala.add(id, name, type, tarikhSakht, tarikhEngheza, price, tozihat, tedad, tarikh); showData(); txt_name.Text = ""; txt_tarikhSakht.Text = ""; txt_tarikhEngheza.Text = ""; txt_price.Text = ""; txt_tozihat.Text = ""; txt_tedad.Text = ""; txt_bedehkar.Text = ""; txt_bestankar.Text = ""; txt_tarikh.Text = ""; txt_factor.Text = ""; } } else { MessageBox.Show("یک سطر انتخاب کنید "); } }