Пример #1
0
 public ActionResult Delete(int[] id)
 {
     foreach (int i in id)
     {
         NongSan ns = db.NongSans.Find(i);
         db.NongSans.Remove(ns);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Пример #2
0
 public ActionResult Edit([Bind(Include = "ID,TenNS,IDLoaiNS,MoTaNgan,MotaChiTiet,NgayTao,NguoiTao,NgayCapNhat,NguoiCapNhat,HinhAnhDaiDien")] NongSan nongSan)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nongSan).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IDLoaiNS = new SelectList(db.LoaiNS, "IDLoaiNS", "TenLoai", nongSan.IDLoaiNS);
     return(View(nongSan));
 }
Пример #3
0
        // GET: Admin/NongSans/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NongSan nongSan = db.NongSans.Find(id);

            if (nongSan == null)
            {
                return(HttpNotFound());
            }
            return(View(nongSan));
        }
Пример #4
0
        // GET: Admin/NongSans/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NongSan nongSan = db.NongSans.Find(id);

            if (nongSan == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IDLoaiNS = new SelectList(db.LoaiNS, "IDLoaiNS", "TenLoai", nongSan.IDLoaiNS);
            return(View(nongSan));
        }
        public Diablog_NS(string id)
        {
            InitializeComponent();
            border();
            NongSanDB db = new NongSanDB();

            ds = busCay.getAllNameTree();
            // MessageBox.Show(ds.Count.ToString());
            comboBoxLoaiCay.DataSource = ds.Values.ToList();
            // load noi dung de sua thong tin
            #region gắn giá trị
            this.id = Convert.ToInt32(id);
            o       = db.getNongSan(id);
            textThoiGianBaoQuan.Text = o.ThoiGianBaoQuan.ToString();
            textSanLuongTonKho.Text  = o.SanLuongTonKho.ToString();
            textDonGia.Text          = o.DonGia.ToString();
            Dictionary <int, string> d;
            using (QLNTEntities1 db1 = new QLNTEntities1())
            {
                d = (
                    from z in db1.Cay
                    select new { z.MaLoaiCay, z.TenCay }

                    ).ToDictionary(z => z.MaLoaiCay, z => z.TenCay);
            }
            var kq = d.Values.ToString();
            foreach (var k in d)
            {
                if (k.Key.ToString() == o.MaLoaiCay.ToString())
                {
                    kq = k.Value.ToString();
                    break;
                }
            }
            comboBoxLoaiCay.Text = kq;
            #endregion
            // An button add
            button_add.Enabled = false;
            button_add.Visible = false;
            //Hien button luu
            button_luu.Visible = true;
            //button_luu.Enabled = false;
        }
        private void button_luu_Click(object sender, EventArgs e)
        {
            if (check())
            {
                var temp = comboBoxLoaiCay.Text;

                /*var re = from c in db.NongSan
                 *       join d in db.Cay on c.MaLoaiCay equals d.MaLoaiCay
                 *       where String.Compare(temp, d.TenCay.ToString(), true);
                 *       select new ()*/
                Dictionary <int, string> d;
                using (QLNTEntities1 db = new QLNTEntities1())
                {
                    d = (
                        from z in db.Cay
                        select new { z.MaLoaiCay, z.TenCay }

                        ).ToDictionary(z => z.MaLoaiCay, z => z.TenCay);
                }

                var key = d.Values;
                var kq  = d.Keys.ToString();
                foreach (var k in d)
                {
                    if (k.Value.ToString() == temp.ToString())
                    {
                        kq = k.Key.ToString();
                        break;
                    }
                }
                //MessageBox.Show(kq);
                o = new NongSan()
                {
                    MaNS = this.id, ThoiGianBaoQuan = Convert.ToInt32(textThoiGianBaoQuan.Text), SanLuongTonKho = Convert.ToDouble(textSanLuongTonKho.Text), DonGia = Convert.ToDouble(textDonGia.Text), MaLoaiCay = Convert.ToInt32(kq)
                };
                bus.Edit(o);
                MessageBox.Show("Sửa thành công");
                Dialog_close();
            }
        }
Пример #7
0
        public void Edit(NongSan o)
        {
            NongSanDB db = new NongSanDB();

            db.Edit(o);
        }
Пример #8
0
        public void Add(NongSan o)
        {
            NongSanDB db = new NongSanDB();

            db.Add(o);
        }
        private void button_add_Click(object sender, EventArgs e)
        {
            if (check())
            {
                var temp = comboBoxLoaiCay.Text;
                Dictionary <int, string> d;
                using (QLNTEntities1 db = new QLNTEntities1())
                {
                    d = (
                        from z in db.Cay
                        select new { z.MaLoaiCay, z.TenCay }

                        ).ToDictionary(z => z.MaLoaiCay, z => z.TenCay);
                }
                var key = d.Values;
                var kq  = d.Keys.ToString();
                foreach (var k in d)
                {
                    if (k.Value.ToString() == temp.ToString())
                    {
                        kq = k.Key.ToString();
                        break;
                    }
                }
                o = new NongSan()
                {
                    ThoiGianBaoQuan = Convert.ToInt32(textThoiGianBaoQuan.Text), SanLuongTonKho = Convert.ToDouble(textSanLuongTonKho.Text), DonGia = Convert.ToDouble(textDonGia.Text), MaLoaiCay = Convert.ToInt32(kq)
                };
                bus.Add(o);
                MessageBox.Show("Thêm thành công");
                Dialog_close();
                //}

                #region kt
                //string t="Tên phân bón : {0} \n Loại: {1} \n Ngày sx: {2} \n hạn sử dụng: {3}";
                //string msg = string.Format(t,o.TenPB,o.Loai,o.NgaySX.ToString("dd//MM/yyyy"), o.HanSD.ToString("dd//MM/yyyy"));
                //MessageBox.Show(msg);

                //DatepickerSX.Value.ToString("dd/MM/yyyy")
                //MessageBox.Show(textTenPB.Text+" " + comboBoxLoai.Text );

                //MessageBox.Show("thành công");
                #endregion
            }

            /*private void bunifuFlatButton1_Click(object sender, EventArgs e)
             * {
             *
             *  if (check())
             *  {
             *      o = new NongSan() { MaNS = this.id, ThoiGianBaoQuan = Convert.ToInt32(textThoiGianBaoQuan.Text), SanLuongTonKho = Convert.ToDouble(textSanLuongTonKho), DonGia = Convert.ToDouble(textDonGia.Text), BaoQuan = textBaoQuan.Text };
             *      bus.Edit(o);
             *
             *      Dialog_close();
             *  }
             * }
             *
             * private void Diablog_NS_Load(object sender, EventArgs e)
             * {
             *  ds = busCay.getAllNameTree();
             *  // MessageBox.Show(ds.Count.ToString());
             *  comboBoxLoaiCay.DataSource = ds.Values.ToList();
             * }*/
        }