private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { int r = this.dataGridView2.CurrentRow.Index; Console.Write(dataGridView2.Rows[r].Cells[1].Value.ToString()); DataTable dt = new DataTable("teble"); dt.Columns.Add("编号", typeof(string)); dt.Columns.Add("名称", typeof(string)); dt.Columns.Add("单位", typeof(String)); dt.Columns.Add("数量", typeof(double)); dt.Columns.Add("单价", typeof(double)); dt.Columns.Add("金额", typeof(double)); dt.Columns.Add("备注", typeof(String)); purchase p = new purchase(); List <purchase_material> ps = new List <purchase_material>(); ps = p.selectMaterial_danhao(dataGridView2.Rows[r].Cells[1].Value.ToString(), 1); foreach (purchase_material p1 in ps) { rawmaterial r1 = new rawmaterial(); rawmaterialdao rdao = new rawmaterialdao(); r1 = rdao.selectNumber(p1.RawMaterial_number); dt.Rows.Add(p1.RawMaterial_number, r1.Rawmaterial_name, p1.Unit, p1.Count, p1.Price, p1.Money, p1.Remark); } dataGridView2.DataSource = dt; } catch (SystemException) { MessageBox.Show("操作有误"); } }
private void rawMaterial_Load(object sender, EventArgs e) { rawmaterialdao p = new rawmaterialdao(); List <rawmaterial> rs = new List <rawmaterial>(); rs = p.find_all1(); Console.Write(rs); DataSet ds = new DataSet(); DataTable dt = new DataTable("Table_New"); dt.Columns.Add("类别", typeof(string)); dt.Columns.Add("编号", typeof(string)); dt.Columns.Add("名称", typeof(String)); dt.Columns.Add("数量", typeof(double)); dt.Columns.Add("单位", typeof(String)); int i = 0; foreach (rawmaterial r1 in rs) { dt.Rows.Add(r1.Rawmaterial_type, r1.Rawmaterial_number, r1.Rawmaterial_name, r1.Rawmaterial_count, r1.Rawmaterial_unit); i++; } dataGridView1.DataSource = dt; data = dataGridView1; }
private void button1_Click_1(object sender, EventArgs e) { try { DataTable dt = new DataTable("teble"); dt.Columns.Add("采购日期", typeof(string)); dt.Columns.Add("单据号", typeof(string)); dt.Columns.Add("供应商", typeof(String)); dt.Columns.Add("商品编号", typeof(string)); dt.Columns.Add("商品名称", typeof(string)); dt.Columns.Add("单位", typeof(string)); dt.Columns.Add("单价", typeof(double)); dt.Columns.Add("数量", typeof(double)); dt.Columns.Add("采购金额", typeof(double)); dt.Columns.Add("备注", typeof(String)); purchase p = new purchase(); List <purchase_material> ps = new List <purchase_material>(); if (comboBox1.Text == "" && textBox1.Text == "") { ps = p.selectMaterial_date(Convert.ToDateTime(dateTimePicker1.Text), Convert.ToDateTime(dateTimePicker2.Text), 0); } if (comboBox1.Text == "" && textBox1.Text != "") { ps = p.selectMaterial_dateandrname(Convert.ToDateTime(dateTimePicker1.Text), Convert.ToDateTime(dateTimePicker2.Text), textBox1.Text, 0); } if (comboBox1.Text != "" && textBox1.Text == "") { string[] suppliername = comboBox1.Text.Split(' '); ps = p.selectMaterial_dateandsnumber(Convert.ToDateTime(dateTimePicker1.Text), Convert.ToDateTime(dateTimePicker2.Text), suppliername[0], 0); } if (comboBox1.Text != "" && textBox1.Text != "") { string[] suppliername = comboBox1.Text.Split(' '); ps = p.selectMaterial_dateandrnameandsupplier(Convert.ToDateTime(dateTimePicker1.Text), Convert.ToDateTime(dateTimePicker2.Text), suppliername[0], textBox1.Text, 0); } foreach (purchase_material p1 in ps) { Console.Write(p1.Danju_id + "姚雅丽呀"); rawmaterial r1 = new rawmaterial(); rawmaterialdao rdao = new rawmaterialdao(); r1 = rdao.selectNumber(p1.RawMaterial_number); supplier s1 = new supplier(); supplierdao sdao = new supplierdao(); s1 = sdao.selectnumber(p1.Suppliernumber); dt.Rows.Add(p1.Dan_date, p1.Danju_id, s1.Supplier_name, r1.Rawmaterial_number, r1.Rawmaterial_name, p1.Unit, p1.Price, p1.Count, p1.Money, p1.Remark); } dataGridView1.DataSource = dt; double money = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { money += Convert.ToDouble(dataGridView1.Rows[i].Cells[8].Value); } label6.Text = money.ToString(); } catch (SystemException) { MessageBox.Show("操作不当"); } }
private void button1_Click_1(object sender, EventArgs e) { if (comboBox1.Text == "类别" && textBox1.Text == "输入编号/名称") { } else if (comboBox1.Text != "类别" && textBox1.Text == "输入编号/名称") { rawmaterialdao p = new rawmaterialdao(); List <rawmaterial> rs = new List <rawmaterial>(); rs = p.selectType(comboBox1.Text); Console.Write(rs); DataSet ds = new DataSet(); DataTable dt = new DataTable("Table_New"); dt.Columns.Add("类别", typeof(string)); dt.Columns.Add("编号", typeof(string)); dt.Columns.Add("名称", typeof(String)); dt.Columns.Add("数量", typeof(double)); dt.Columns.Add("单位", typeof(String)); foreach (rawmaterial r1 in rs) { dt.Rows.Add(r1.Rawmaterial_type, r1.Rawmaterial_number, r1.Rawmaterial_name, r1.Rawmaterial_count, r1.Rawmaterial_unit); } dataGridView1.DataSource = dt; } else if (comboBox1.Text == "类别" && textBox1.Text != "输入编号/名称") { rawmaterialdao p = new rawmaterialdao(); List <rawmaterial> rs = new List <rawmaterial>(); rs = p.selectNumberOrName(textBox1.Text); Console.Write(rs); DataSet ds = new DataSet(); DataTable dt = new DataTable("Table_New"); dt.Columns.Add("类别", typeof(string)); dt.Columns.Add("编号", typeof(string)); dt.Columns.Add("名称", typeof(string)); dt.Columns.Add("数量", typeof(double)); dt.Columns.Add("单位", typeof(String)); foreach (rawmaterial r1 in rs) { dt.Rows.Add(r1.Rawmaterial_type, r1.Rawmaterial_number, r1.Rawmaterial_name, r1.Rawmaterial_count, r1.Rawmaterial_unit); } dataGridView1.DataSource = dt; } data = dataGridView1; }
private void Form1_Load(object sender, EventArgs e) { // TODO: 这行代码将数据加载到表“lemonDataSet.supplier”中。您可以根据需要移动或删除它。 //panel1.Visible = false; //自动生成单据 purchase p = new purchase(); int P_Int_newBillCode = p.selectMaxdanjuid() + 1;//记录单据编号中的数字码 textBox1.Text = DateTime.Now.ToString("yyyyMMdd") + "HappyLemon" + P_Int_newBillCode; rawmaterial r1 = new rawmaterial(); rawmaterialdao dao = new rawmaterialdao(); //int index=this.purchaseTable.Rows.Add(); //Console.Write(number1[0]); if (number1 == null) { } else { foreach (string i in number1) { r1 = dao.selectNumber(i); if (r1 == null) { } else { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = r1.Rawmaterial_number; this.dataGridView1.Rows[index].Cells[1].Value = r1.Rawmaterial_name; this.dataGridView1.Rows[index].Cells[3].Value = r1.Rawmaterial_unit; } } } dataGridView1.Focus(); //使表格获得鼠标焦点 supplier_text.Focus(); //使供应商文本框成为焦点 //datagridview2 }
private void button4_Click(object sender, EventArgs e) { bool b = true; if (dataGridView1.Rows.Count == 1) { MessageBox.Show("请填写信息"); b = false; } else { for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (dataGridView1.Rows[i].Cells[0].Value == null) { MessageBox.Show("编号不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[1].Value == null) { MessageBox.Show("商品名称不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[3].Value == null) { MessageBox.Show("单位不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[4].Value == null) { MessageBox.Show("数量不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[5].Value == null) { MessageBox.Show("单价不能为空"); b = false; } else if (dataGridView1.Rows[i].Cells[6].Value == null) { MessageBox.Show("金额不能为空"); b = false; } else if (textBox1.Text == "") { MessageBox.Show("请选择供应商"); b = false; } else if (textBox3.Text == "") { MessageBox.Show("操作人不能为空!"); } } } if (b == false) { } else { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("是否确认保存?", "提交", messButton); if (dr == DialogResult.OK) { string[] supplier = supplier_text.Text.Split(' '); string[] employer = textBox3.Text.Split(' '); try { purchase dao = new purchase(); double mm = Convert.ToDouble(label11.Text); dao.addDanju(Convert.ToDateTime(dateTimePicker1.Text), textBox1.Text, employer[0], mm, textBox4.Text, supplier[0], 0); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { purchase_material p = new purchase_material(); Console.Write(dataGridView1.Rows[i].Cells[0].Value + "lallalalaalalalalalalla"); p.RawMaterial_number = dataGridView1.Rows[i].Cells[0].Value.ToString(); rawmaterialDaoz rdd = new rawmaterialDaoz(); rawmaterialdao rdao = new rawmaterialdao(); rawmaterial r = rdao.selectNumber(p.RawMaterial_number); if (r == null) { rdd.addRawmaterial(p.RawMaterial_number, dataGridView1.Rows[i].Cells[1].Value.ToString(), "其他", 0, dataGridView1.Rows[i].Cells[3].Value.ToString()); } p.Suppliernumber = supplier[0]; p.Dan_date = Convert.ToDateTime(dateTimePicker1.Text); Console.Write("这是一个人" + p.Suppliernumber + "这是一个人"); p.Unit = dataGridView1.Rows[i].Cells[3].Value.ToString(); p.Count = Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value); p.Price = Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value); //Console.Write("这是一个人" + p.Price + "这是一个人"); p.Money = Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value); if (dataGridView1.Rows[i].Cells[7].Value == null) { p.Remark = ""; } else { p.Remark = dataGridView1.Rows[i].Cells[7].Value.ToString(); } p.Status = 0; p.Danju_id = textBox1.Text; // Console.Write("这是一个人" + p.Danju_id + "这是一个人"); dao.addpurchase(p); } MessageBox.Show("保存成功"); dataGridView1.Rows.Clear(); } catch (SystemException) { MessageBox.Show("操作有误"); } } else { } } }