Beispiel #1
0
        public void addpurchase(purchase_material p)
        {
            MySqlConnection conn = Util.Util.getConn();
            MySqlCommand    command;

            try
            {
                command             = conn.CreateCommand();
                command.CommandText = "INSERT INTO purchase_material(rawMaterial_number,suppliernumber,unit,count,price,money,remark,dan_date,status,danju_id) VALUES(@rawMaterial_id,@supplierid,@unit,@count,@price,@money,@remark,@dan_date,@status,@danju_id)";
                command.Parameters.AddWithValue("@rawMaterial_id", p.RawMaterial_number);
                command.Parameters.AddWithValue("@supplierid", p.Suppliernumber);
                command.Parameters.AddWithValue("@unit", p.Unit);
                command.Parameters.AddWithValue("@count", p.Count);
                command.Parameters.AddWithValue("@price", p.Price);
                command.Parameters.AddWithValue("@money", p.Money);
                command.Parameters.AddWithValue("@remark", p.Remark);
                command.Parameters.AddWithValue("@dan_date", p.Dan_date);
                command.Parameters.AddWithValue("@status", p.Status);
                command.Parameters.AddWithValue("@danju_id", p.Danju_id);
                command.ExecuteNonQuery();
                //MessageBox.Show("插入成功");
            }
            catch (Exception)
            {
                MessageBox.Show("插入失败");
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Beispiel #2
0
        //根据日期和供应商、原材料名称查询purchase_material表中status为0的数据
        public List <purchase_material> selectMaterial_dateandrnameandsupplier(DateTime date1, DateTime date2, string suppliernumber, string name, int status)
        {
            MySqlConnection          conn       = Util.Util.getConn();
            MySqlDataReader          dataReader = null;
            MySqlCommand             command    = null;
            purchase_material        r          = null;
            List <purchase_material> rs         = new List <model.purchase_material>();

            try
            {
                command             = conn.CreateCommand();
                command.CommandText = "SELECT * FROM purchase_material where dan_date>='" + date1 + "' and dan_date<='" + date2 + "' and rawMaterial_number=(select rawMaterial_number from rawmaterial where rawMaterial_name like '%" + name + "%') and suppliernumber='" + suppliernumber + "' and status =" + status;
                dataReader          = command.ExecuteReader();
                Console.WriteLine();
                while (dataReader.Read())
                {
                    r    = new purchase_material();
                    r.Id = dataReader.GetInt16(0);
                    r.RawMaterial_number = dataReader.GetString(1);
                    r.Suppliernumber     = dataReader.GetString(2);
                    r.Unit     = dataReader.GetString(3);
                    r.Count    = dataReader.GetDouble(4);
                    r.Price    = dataReader.GetDouble(5);
                    r.Money    = dataReader.GetDouble(6);
                    r.Remark   = dataReader.GetString(7);
                    r.Dan_date = dataReader.GetDateTime(8);
                    r.Status   = dataReader.GetInt16(9);
                    r.Danju_id = dataReader.GetString(10);
                    Console.Write("瑶瑶李");
                    rs.Add(r);
                    Console.Write("瑶瑶李");
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(rs);
        }
        private void button4_Click_1(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(label9.Text);
                        dao.addDanju(Convert.ToDateTime(dateTimePicker1.Text), textBox1.Text, employer[0], mm, textBox4.Text, supplier[0], 1);

                        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();
                            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   = 1;
                            p.Danju_id = textBox1.Text;
                            // Console.Write("这是一个人" + p.Danju_id + "这是一个人");
                            dao.addpurchase(p);
                        }
                        MessageBox.Show("保存成功");
                    }
                    catch (SystemException)
                    {
                        MessageBox.Show("操作有误");
                    }
                }
                else
                {
                }
            }
        }
        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 (supplier_text.Text == "")
                    {
                        MessageBox.Show("请选择供应商");
                        b = false;
                    }
                }
            }
            if (b == false)
            {
            }
            else
            {
                purchase dao = new purchase();
                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();
                    p.Suppliernumber     = supplier_text.Text;
                    p.Dan_date           = Convert.ToDateTime(dateTimePicker1.Text);

                    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);
                    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 = 1;
                    dao.addpurchase(p);
                }
                MessageBox.Show("保存成功");
            }
        }