Example #1
0
        private void 新增_Load(object sender, EventArgs e)
        {
            netEntities1 db  = new netEntities1();
            var          gys = from p in db.gys select p;

            comboBox1.ValueMember   = "gysid";
            comboBox1.DisplayMember = "gysname";
            comboBox1.DataSource    = gys.ToList();
            var zl = from p in db.zl select p;

            comboBox2.ValueMember   = "zlid";
            comboBox2.DisplayMember = "zlname";
            comboBox2.DataSource    = zl.ToList();
            if (mode == "update")
            {
                string a1   = spid.ToString();
                sp     new1 = db.sp.SingleOrDefault(a => a.spid == a1);
                label5.Text             = new1.spid;
                textBox1.Text           = new1.spname;
                comboBox1.SelectedValue = new1.spgysid;
                comboBox2.SelectedValue = new1.spzlid;
            }
            if (spid == "0")
            {
                label5.Text  = "自动生成";
                button1.Text = "新增";
            }
            else
            {
                button1.Text = "修改";
            }
        }
Example #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            netEntities1 db = new netEntities1();

            if (dataGridView1.SelectedRows.Count > 0)
            {
                string id   = dataGridView1.SelectedRows[0].Cells["spid"].Value.ToString();
                sp     new1 = db.sp.SingleOrDefault(a => a.spid == id);
                db.sp.Remove(new1);
                db.SaveChanges();
                MessageBox.Show("删除成功!");
                var sj = from a in db.sp select new { a.spid, a.spname, a.spgysid, a.spzlid };
                dataGridView1.DataSource = sj.ToList();
            }
            else
            {
                MessageBox.Show("请先选择行!");
            }
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            netEntities1 db   = new netEntities1();
            sp           new1 = new sp();

            new1.spzlid  = Convert.ToString(comboBox2.SelectedValue);
            new1.spgysid = Convert.ToString(comboBox1.SelectedValue);
            if (mode == "insert")
            {
                string a = DateTime.Now.Ticks.ToString();
                a         = a.Substring(a.Length - 7);
                new1.spid = a;
                db.sp.Add(new1);
            }
            if (mode == "update")
            {
                new1.spid = label5.Text;
                db.Entry <sp>(new1).State = EntityState.Modified;
            }

            new1.spname = textBox1.Text;
            db.SaveChanges();
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }