public bool editDC(DOCHOI dc) { bool chek = false; using (ContextEntites context = new ContextEntites()) { try { var s = context.DOCHOIs.Single(x => x.MADC == dc.MADC); s.TENDC = dc.TENDC; s.SL = dc.SL; s.NUOCSX = dc.NUOCSX; s.LOAI = dc.LOAI; s.GIA = dc.GIA; if (context.SaveChanges() >= 0) { chek = true; } } catch (Exception ec) { Console.WriteLine(ec.ToString()); } } return(chek); }
public ActionResult Themmoidochoi(DOCHOI dochoi, HttpPostedFileBase fileUpload) { ViewBag.MaCD = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.Tenchude), "MaCD", "Tenchude"); ViewBag.MaTH = new SelectList(db.THUONGHIEUx.ToList().OrderBy(n => n.Tenthuonghieu), "MaTH", "Tenthuonghieu"); if (fileUpload == null) { ViewBag.Thongbao = "Hãy chọn ảnh sản phẩm"; return(View()); } else { if (ModelState.IsValid) { var fileName = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } dochoi.Hinhminhhoa = fileUpload.FileName; db.DOCHOIs.Add(dochoi); db.SaveChanges(); } return(RedirectToAction("Dochoi")); } }
private void btn_nhap_Click(object sender, EventArgs e) { if (locked) { return; } try { if (string.IsNullOrEmpty(tb_masp.Text) || string.IsNullOrEmpty(tb_tenDC.Text) || int.Parse(tb_SL.Text) == 0 || string.IsNullOrEmpty(tb_SL.Text)) { MessageBox.Show("Thiếu Dữ Liệu!"); return; } CTPHIEUNHAP ct = new CTPHIEUNHAP(); if (!masp_avail) { DoChoiBus dcBus = new DoChoiBus(); DOCHOI dc = new DOCHOI(); dc.MADC = int.Parse(tb_masp.Text); dc.SL = int.Parse(tb_SL.Text);//edit dc.SL=0; dc.GIA = double.Parse(tb_GiaBan.Text); //listNewDC.Add(dc); } ///<summary> ///hậu ///</summary> CTPHIEUNHAP ctph = new CTPHIEUNHAP(); ctph.MAPHIEU = phieu.MAPHIEU; ctph.MADC = int.Parse(tb_masp.Text); ctph.SL = int.Parse(tb_SL.Text); ctph.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ctph.SL; tong_giatri += (double)ctph.GIANHAP; tong_sl += (int)ctph.SL; var li = listCTPN.Where(i => i.MADC == ctph.MADC); if (li.Count() > 0) { li.First().SL += ctph.SL; li.First().GIANHAP += ctph.GIANHAP; } else { listCTPN.Add(ctph); } refreshDataGrid(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public ActionResult Suadochoi(DOCHOI dochoi, FormCollection f) { if (ModelState.IsValid) { db.Entry(dochoi).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } ViewBag.MaCD = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.Tenchude), "MaCD", "Tenchude", dochoi.MaCD); ViewBag.MaTH = new SelectList(db.THUONGHIEUx.ToList().OrderBy(n => n.Tenthuonghieu), "MaTH", "Tenthuonghieu", dochoi.MaTH); ViewBag.MaDC = dochoi.MaDC; return(RedirectToAction("Dochoi")); }
public ActionResult Xoadochoi(int id) { DOCHOI dochoi = db.DOCHOIs.SingleOrDefault(n => n.MaDC == id); ViewBag.MaDC = dochoi.MaDC; if (dochoi == null) { Response.StatusCode = 404; return(null); } return(View(dochoi)); }
public ActionResult Suadochoi(int id) { DOCHOI dochoi = db.DOCHOIs.SingleOrDefault(n => n.MaDC == id); if (dochoi == null) { Response.StatusCode = 404; return(null); } ViewBag.MaCD = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.Tenchude), "MaCD", "Tenchude", dochoi.MaCD); ViewBag.MaTH = new SelectList(db.THUONGHIEUx.ToList().OrderBy(n => n.Tenthuonghieu), "MaTH", "Tenthuonghieu", dochoi.MaTH); return(View(dochoi)); }
public ActionResult XacnhanXoadochoi(int id) { DOCHOI dochoi = db.DOCHOIs.SingleOrDefault(n => n.MaDC == id); ViewBag.MaDC = dochoi.MaDC; if (dochoi == null) { Response.StatusCode = 404; return(null); } db.DOCHOIs.Remove(dochoi); db.SaveChanges(); return(RedirectToAction("Dochoi")); }
public DOCHOI DochoiById(int ID) { DOCHOI dc = new DOCHOI(); using (ContextEntites context = new ContextEntites()) { var a = context.DOCHOIs.Single(x => x.MADC == ID); dc.MADC = a.MADC; dc.NUOCSX = a.NUOCSX; dc.SL = a.SL; dc.TENDC = a.TENDC; dc.LOAI = a.LOAI; dc.GIA = a.GIA; } return(dc); }
public int AddDoChoi(DOCHOI dc) { int s = 0; using (ContextEntites context = new ContextEntites()) { try { context.DOCHOIs.Add(dc); s = context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } return(s); }
private void btn_Sua_Click(object sender, EventArgs e) { try { if (tbl_DsDc.SelectedRows.Count > 0) { if (data_change_status) { DoChoiBus dcBus = new DoChoiBus(); DOCHOI dc = new DOCHOI(); dc.MADC = (int)tbl_DsDc.SelectedRows[0].Cells["MADC"].Value; dc.TENDC = tb_TenDC.Text; if (string.IsNullOrEmpty(tb_Loai.Text)) { dc.LOAI = tb_Loai.Text; } dc.GIA = double.Parse(tb_Gia.Text); if (string.IsNullOrEmpty(tb_NuocSX.Text)) { dc.NUOCSX = tb_NuocSX.Text; } dc.SL = int.Parse(tb_SL.Text); dcBus.editDC(dc); ThongKeKho_Load(sender, e); MessageBox.Show("Đã sửa thành công!!"); } else { MessageBox.Show("Chưa có thông tin đc thay đổi!!"); } } else { MessageBox.Show("Bạn chưa chọn Hàng để sửa!!"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show(ex.Message); } }
private void bt_Nhap_Click(object sender, EventArgs e) { try { DoChoiBus dcBus = new DoChoiBus(); DOCHOI dc = new DOCHOI(); dc = dcBus.DochoiById(int.Parse(cb_masp.Text)); dc.SL = int.Parse(tb_slSP.Text); dc.GIA = ((double)dc.GIA * (double)dc.SL); bool c = true; foreach (DOCHOI i in listDC) { if (dc.MADC == i.MADC) { i.SL += dc.SL; i.GIA += dc.GIA; c = false; break; } } if (c) { listDC.Add(dc); } so_sp += (int)dc.SL; tien_tong += ((double)dc.GIA); setDefaultValue(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public bool deleteDC(int maDC) { bool check = false; using (ContextEntites con = new ContextEntites()) { try { DOCHOI hd = con.DOCHOIs.Single(x => x.MADC == maDC); con.DOCHOIs.Remove(hd); if (con.SaveChanges() >= 0) { check = true; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } return(check); }
public List <DOCHOI> DSDoChoibyID(int madc) { List <DOCHOI> listDoChoi = new List <DOCHOI>(); using (ContextEntites context = new ContextEntites()) { var query = (from c in context.DOCHOIs where c.MADC == madc select new { c.MADC, c.SL, c.TENDC, c.NUOCSX, c.LOAI, c.GIA }); foreach (var a in query) { DOCHOI dc = new DOCHOI(); dc.MADC = a.MADC; dc.NUOCSX = a.NUOCSX; dc.SL = a.SL; dc.TENDC = a.TENDC; dc.LOAI = a.LOAI; dc.GIA = a.GIA; listDoChoi.Add(dc); } } return(listDoChoi); }
public bool reduceDC(DOCHOI dc, int sl) { bool chek = false; using (ContextEntites context = new ContextEntites()) { try { var s = context.DOCHOIs.Single(x => x.MADC == dc.MADC); s.SL = s.SL - sl; if (context.SaveChanges() >= 0) { chek = true; } } catch (Exception ec) { Console.WriteLine(ec.ToString()); } } return(chek); }
public bool editDC(DOCHOI dc) { return(dcdao.editDC(dc)); }
private void btn_nhap_Click(object sender, EventArgs e) { if (locked) { return; } try { if (string.IsNullOrEmpty(tb_masp.Text) || string.IsNullOrEmpty(tb_tenDC.Text) || int.Parse(tb_SL.Text) == 0 || string.IsNullOrEmpty(tb_SL.Text)) { MessageBox.Show("Thiếu Dữ Liệu!"); return; } CTPHIEUNHAP ct = new CTPHIEUNHAP(); if (masp_avail == false) { DoChoiBus dcBus = new DoChoiBus(); DOCHOI dc = new DOCHOI(); dc.MADC = int.Parse(tb_masp.Text); dc.SL = int.Parse(tb_SL.Text);//edit dc.SL=0; dc.GIA = double.Parse(tb_GiaBan.Text); dc.LOAI = tb_loai.Text; dc.NUOCSX = tb_ncsx.Text; dc.TENDC = tb_tenDC.Text; // dcBus.AddDoChoi(dc); listDc.Add(dc); ct.MADC = dc.MADC; ct.MAPHIEU = phieu.MAPHIEU; ct.SL = (int)dc.SL; ct.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ct.SL; listCTPN.Add(ct); } else { masp_avail = true; var li = listCTPN.Where(i => i.MADC == ct.MADC); if (li.Count() > 0) { li.First().SL += ct.SL; li.First().GIANHAP += ct.GIANHAP; } ct.MADC = int.Parse(tb_masp.Text); ct.MAPHIEU = phieu.MAPHIEU; ct.SL = int.Parse(tb_SL.Text); ct.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ct.SL; listCTPN.Add(ct); } ///<summary> ///hậu ///</summary> //CTPHIEUNHAP ctph = new CTPHIEUNHAP(); //ctph.MAPHIEU = phieu.MAPHIEU; //ctph.MADC = int.Parse(tb_masp.Text); //ctph.SL = int.Parse(tb_SL.Text); //ctph.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ctph.SL; //tong_giatri += (double)ctph.GIANHAP; //tong_sl += (int)ctph.SL; //var li = listCTPN.Where(i => i.MADC == ctph.MADC); //if (li.Count() > 0) //{ // li.First().SL += ctph.SL; // li.First().GIANHAP += ctph.GIANHAP; //} //else // listCTPN.Add(ctph); tong_giatri += (double)ct.GIANHAP; tong_sl += (int)ct.SL; refresh(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public int AddDoChoi(DOCHOI dc) { return(dcdao.AddDoChoi(dc)); }