private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { Console.Write("1"); try { int r = this.dataGridView2.CurrentRow.Index; Console.Write("2"); 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)); sale p = new sale(); List <sale_good> ps = new List <sale_good>(); Console.Write("3"); ps = p.selectMaterial_danhao(dataGridView2.Rows[r].Cells[1].Value.ToString()); foreach (sale_good p1 in ps) { good r1 = new good(); gooddao rdao = new gooddao(); r1 = rdao.selectNumber(p1.Good_number); dt.Rows.Add(p1.Good_number, r1.Good_name, p1.Unit, p1.Count, p1.Price, p1.Money, p1.Remark); } dataGridView2.DataSource = dt; } catch (SystemException) { MessageBox.Show("操作有误"); } }
private void button1_Click(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)); sale p = new sale(); List <sale_good> ps = new List <sale_good>(); if (comboBox1.Text == "" && textBox1.Text == "") { ps = p.selectMaterial_date(Convert.ToDateTime(dateTimePicker1.Text), Convert.ToDateTime(dateTimePicker2.Text)); } if (comboBox1.Text == "" && textBox1.Text != "") { ps = p.selectMaterial_dateandrname(Convert.ToDateTime(dateTimePicker1.Text), Convert.ToDateTime(dateTimePicker2.Text), textBox1.Text); } if (comboBox1.Text != "" && textBox1.Text == "") { string[] suppliername = comboBox1.Text.Split(' '); ps = p.selectMaterial_dateandsnumber(Convert.ToDateTime(dateTimePicker1.Text), Convert.ToDateTime(dateTimePicker2.Text), suppliername[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); } foreach (sale_good p1 in ps) { Console.Write(p1.Danju_id + "姚雅丽呀"); good r1 = new good(); gooddao rdao = new gooddao(); r1 = rdao.selectNumber(p1.Good_number); customer s1 = new customer(); customerdao sdao = new customerdao(); s1 = sdao.selectnumber(p1.Customernumber); dt.Rows.Add(p1.Dan_date, p1.Danju_id, s1.Customer_name, r1.Good_number, r1.Good_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 Form1_Load(object sender, EventArgs e) { // TODO: 这行代码将数据加载到表“lemonDataSet.customer”中。您可以根据需要移动或删除它。 //panel1.Visible = false; //自动生成单据 sale p = new sale(); int P_Int_newBillCode = p.selectMaxdanjuid() + 1;//记录单据编号中的数字码 textBox1.Text = DateTime.Now.ToString("yyyyMMdd") + "HappyLemon_sale" + P_Int_newBillCode; // label9.Focus(); panel1.Visible = false; good r1 = new good(); gooddao dao = new gooddao(); //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.Good_number; this.dataGridView1.Rows[index].Cells[1].Value = r1.Good_name; this.dataGridView1.Rows[index].Cells[3].Value = r1.Good_unit; this.dataGridView1.Rows[index].Cells[5].Value = r1.Good_price; } } } dataGridView1.Focus(); //使表格获得鼠标焦点 supplier_text.Focus(); //使供应商文本框成为焦点 //datagridview2 }