Exemplo n.º 1
0
 // 删除按钮-删除
 private void button3_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count > 0)
     {
         string       key = this.dataGridView1.SelectedRows[0].Cells["货物代码"].Value.ToString();
         DialogResult jo  = MessageBox.Show("要删除货物代码为" + key + "的那一行吗?", "确认删除", MessageBoxButtons.OKCancel);
         if (jo == DialogResult.OK)
         {
             // goods删除
             var query = (from g in db.goods where g.货物代码 == key select g).FirstOrDefault();
             if (query != null)
             {
                 // 删除信息
                 db.goods.Remove(query);
                 db.SaveChanges();
                 // 刷新信息
                 this.button5.PerformClick();
             }
         }
     }
     else
     {
         MessageBox.Show("请选择行!", "提示信息");
     }
 }
Exemplo n.º 2
0
        // 提交信息
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "")
            {
                MessageBox.Show("不能为空!", "提示消息");
            }
            else
            {
                string   gid      = textBox1.Text.Trim();
                string   name     = textBox2.Text.Trim();
                string   number   = textBox3.Text.Trim();
                DateTime date     = DateTime.Parse(dateTimePicker1.Text);
                string   unit     = textBox4.Text.Trim();
                string   stock    = textBox5.Text.Trim();
                decimal  price    = Convert.ToDecimal(textBox6.Text.Trim());
                int      type     = Convert.ToInt16(comboBox1.SelectedValue.ToString());
                int      supplier = Convert.ToInt16(comboBox2.SelectedValue.ToString());
                goods    g        = new goods();

                g.货物代码 = gid;
                g.货物名称 = name;
                g.库存量  = stock;
                g.类型   = type;
                g.单位   = unit;
                g.入库日期 = date;
                g.售价   = price;
                g.入库单号 = number;
                g.供应商  = supplier;
                db.goods.Add(g);
                db.SaveChanges();
                MessageBox.Show("商品添加成功!", "提示信息");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }