//向盘点表增加一次盘点信息
        public static bool add_pandian(inventory_rawmaterial r)
        {
            MySqlConnection conn = Util.Util.getConn();
            MySqlCommand    command;

            try
            {
                command             = conn.CreateCommand();
                command.CommandText = "INSERT INTO inventory_rawmaterial(id,rawMaterial_number," +
                                      "system_stock,inventory_stock,result) VALUES(" + r.Id + ",'" + r.RawMaterial_number +
                                      "'," + r.System_stock + "," + r.Inventory_stock + ",'" + r.Result + "')";
                Console.WriteLine("sql:" + command.CommandText);
                command.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(true);
        }
Exemple #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         int  i        = count;
         bool wanzheng = true;//是否输入盘点结果
         for (int j = 0; j < i; j++)
         {
             if (dataGridView1.Rows[j].Cells[5].Value == null)
             {
                 MessageBox.Show("请输入盘点结果!");
                 wanzheng = false;
                 break;
             }
         }
         string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
         if (wanzheng == true)
         {
             if (dao.rawmaterialDaow.add_pandian(date))
             {
                 int id = dao.rawmaterialDaow.find_pandianId(date);
                 inventory_rawmaterial r = new inventory_rawmaterial();
                 for (int j = 0; j < count; j++)
                 {
                     r.Id = id;
                     r.RawMaterial_number = Convert.ToString(dataGridView1.Rows[j].Cells[0].Value);
                     r.System_stock       = Convert.ToInt32(dataGridView1.Rows[j].Cells[4].Value);
                     r.Inventory_stock    = Convert.ToInt32(dataGridView1.Rows[j].Cells[5].Value);
                     r.Result             = Convert.ToString(dataGridView1.Rows[j].Cells[6].Value);
                     dao.rawmaterialDaow.add_pandian(r);
                 }
                 MessageBox.Show("保存成功!");
                 dataGridView1.Rows.Clear();
             }
             else
             {
                 MessageBox.Show("保存失败!");
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("你的操作有误!");
     }
 }