Esempio n. 1
0
 private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     try {
         if (state == true)//输入时,初始化界面完成,输入商品编号时,如果原材料表中有此原材料,则输出原材料的其他信息
         {
             if (e.ColumnIndex == 0 && e.RowIndex >= 0)
             {
                 string            number = dataGridView2.CurrentRow.Cells[0].Value.ToString();
                 model.rawmaterial r      = dao.rawmaterialDaow.find_oneRawmaterial(number);
                 if (r != null)
                 {
                     dataGridView2.CurrentRow.Cells[1].Value = r.Rawmaterial_name;
                     dataGridView2.CurrentRow.Cells[2].Value = r.Rawmaterial_type;
                     dataGridView2.CurrentRow.Cells[3].Value = r.Rawmaterial_unit;
                     had.Add(e.RowIndex);
                 }
             }
             if (dataGridView2.Rows[e.RowIndex].Cells[5].Value != null && dataGridView2.Rows[e.RowIndex].Cells[6].Value != null)
             {
                 string danjia   = dataGridView2.Rows[e.RowIndex].Cells[5].Value.ToString();
                 string shuliang = dataGridView2.Rows[e.RowIndex].Cells[6].Value.ToString();
                 double money    = double.Parse(danjia) * double.Parse(shuliang);
                 dataGridView2.Rows[e.RowIndex].Cells[7].Value = money;
             }
         }
     }catch (Exception) {
         MessageBox.Show("你的操作有误!");
     }
 }
Esempio n. 2
0
        private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try {
                if (state == true)//输入时,初始化界面完成,输入商品编号时,如果原材料表中有此原材料,则输出原材料的其他信息,如果没有则提示“编号输入错误”
                {
                    if (e.ColumnIndex == 0 && e.RowIndex >= 0)
                    {
                        if (dataGridView2.CurrentRow.Cells[0].Value.ToString() != "")
                        {
                            string            number = dataGridView2.CurrentRow.Cells[0].Value.ToString();
                            model.rawmaterial r      = dao.rawmaterialDaow.find_oneRawmaterial2(number);

                            if (r != null)
                            {
                                dataGridView2.CurrentRow.Cells[1].Value = r.Rawmaterial_name;
                                dataGridView2.CurrentRow.Cells[2].Value = r.Rawmaterial_type;
                                dataGridView2.CurrentRow.Cells[3].Value = r.Rawmaterial_unit;
                                dataGridView2.CurrentRow.Cells[4].Value = r.Rawmaterial_count;
                                had.Add(r.Rawmaterial_count);
                            }
                            else
                            {
                                MessageBox.Show("商品编号输入错误!\n 请重新输入商品编号!");
                                dataGridView2.Rows[e.RowIndex].ReadOnly = true;
                                dataGridView2[e.RowIndex, 0].ReadOnly   = false; //除了商品编号其他单元格不可编辑
                                dataGridView2.CurrentRow.Cells[0].Value = "";    //清空商品编号
                            }
                        }
                    }

                    if (dataGridView2.Rows[e.RowIndex].Cells[4].Value != null && dataGridView2.Rows[e.RowIndex].Cells[5].Value != null)
                    {
                        string danjia   = dataGridView2.Rows[e.RowIndex].Cells[4].Value.ToString();
                        string shuliang = dataGridView2.Rows[e.RowIndex].Cells[5].Value.ToString();
                        double money    = double.Parse(danjia) * double.Parse(shuliang);
                        dataGridView2.Rows[e.RowIndex].Cells[6].Value = money;
                    }
                }
            }catch (Exception) {
                MessageBox.Show("你的操作有误!");
            }
        }
Esempio n. 3
0
        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                bool wanzheng = true;                                //是否输入完整
                bool baocun   = true;
                for (int j = 0; j < dataGridView2.RowCount - 1; j++) //判断是否输入完整
                {
                    for (int k = 0; k < 8; k++)
                    {//列号
                        if (dataGridView2.Rows[j].Cells[k].Value == null)
                        {
                            wanzheng = false;
                        }
                    }
                }
                if (wanzheng == false)
                {
                    MessageBox.Show("请输入完整!");
                }
                else
                {
                    for (int j = 0; j < dataGridView2.RowCount - 1; j++)//向数据库写入
                    {
                        model.inventory_rawmaterial inr = new model.inventory_rawmaterial();
                        model.rawmaterial           raw = new model.rawmaterial();
                        raw.Rawmaterial_number = dataGridView2.Rows[j].Cells[0].Value.ToString();
                        raw.Rawmaterial_name   = dataGridView2.Rows[j].Cells[1].Value.ToString();
                        raw.Rawmaterial_type   = dataGridView2.Rows[j].Cells[2].Value.ToString();
                        raw.Rawmaterial_unit   = dataGridView2.Rows[j].Cells[3].Value.ToString();
                        string cou = dataGridView2.Rows[j].Cells[5].Value.ToString();
                        raw.Rawmaterial_count = double.Parse(cou);

                        model.instock_rawmaterial ins = new model.instock_rawmaterial();
                        ins.RawMaterial_number = dataGridView2.Rows[j].Cells[0].Value.ToString();
                        ins.RawMaterial_count  = double.Parse(cou);
                        string danjia = dataGridView2.Rows[j].Cells[6].Value.ToString();
                        ins.RawMaterial_danjia   = double.Parse(danjia);
                        ins.RawMaterial_money    = ins.RawMaterial_count * ins.RawMaterial_danjia;
                        ins.RawMaterial_supplier = gongying[j];
                        if (dataGridView2.Rows[j].Cells[8].Value == null)
                        {
                            ins.Mark = "";
                        }
                        else
                        {
                            ins.Mark = dataGridView2.Rows[j].Cells[8].Value.ToString();
                        }
                        ins.Danju_number = label10.Text;

                        model.instock_order or = new model.instock_order();
                        or.Danju_number = label10.Text;
                        or.Date         = dateTimePicker1.Text;
                        if (had.Contains(j) == true)//增加数量
                        {
                            if (dao.rawmaterialDaow.update_rawmaterialCount(raw) == false)
                            {
                                MessageBox.Show("保存失败!");
                                baocun = false;
                            }
                        }
                        else
                        {
                            if (dao.rawmaterialDaow.add_rawmaterial(raw) == false)
                            {
                                MessageBox.Show("保存失败!");
                                baocun = false;
                            }
                        }
                        if (dao.rawmaterialDaow.add_instock(ins) == false)
                        {
                            MessageBox.Show("保存失败!");
                            baocun = false;
                        }
                        if (dao.rawmaterialDaow.add_instockOrder(or) == false)
                        {
                            MessageBox.Show("保存失败!");
                            baocun = false;
                        }
                    }
                    if (baocun == true)
                    {
                        MessageBox.Show("保存成功!");
                        dataGridView2.Rows.Clear();
                        sum = 0;
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("你的操作有误!");
            }
        }