Example #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string suppliesName  = tb_suppliesName.Text;
                string specification = tb_specification.Text;
                string sort          = tb_sort.Text;
                var    db            = new DBAccess_MySql("MySql");
                dataGridView1.Columns.Clear();
                string outString = "";

                //查询物料表中是否重复物料
                DBAccess_MySql dby = new DBAccess_MySql();
                sql = "SELECT * FROM goods_info WHERE goods_name = '" + suppliesName + "' AND goods_code = '" + specification + "'";
                dby = db.ReturnSQL_String(sql, out outString);
                string goodsName = null;
                string goodsCode = null;
                try
                {
                    while (dby.rec.Read())
                    {
                        goodsName = dby.rec.GetString(1);
                        goodsCode = dby.rec.GetString(2);
                    }
                    dby.connMysql.Close();
                }
                catch
                {
                }
                if (goodsCode == suppliesName && goodsName == specification)
                {
                    update_goodInfo();
                    MessageBox.Show("已录入该物料产品!");
                }
                else
                {
                    if (specification == "" || sort == "")
                    {
                        sql = "INSERT into goods_info(goods_name) VALUES('" + suppliesName + "')";
                        db.ExecSql(sql, out outString);
                    }
                    else
                    {
                        sql = "INSERT into goods_info(goods_name,goods_code,goods_height) VALUES('" + suppliesName + "','" + specification + "','" + sort + "')";
                        var rlt = db.ExecSql(sql, out outString);
                    }
                }
                update_goodInfo();
            }
            catch
            {
                MessageBox.Show("重复操作!");
            }
        }