public HttpResponseMessage GetAll()
 {
     try
     {
         HttpResponseMessage reponse = null;
         var           entity        = db.NhaCungCaps.ToList();
         List <NCCDTO> ListNCC       = new List <NCCDTO>();
         if (entity.Count <= 0)
         {
             reponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không Có Dữ Liệu");
         }
         else
         {
             foreach (var item in entity)
             {
                 NCCDTO ncc = new NCCDTO();
                 ncc.MaNCC       = item.MaNCC;
                 ncc.TenNCC      = item.TenNCC;
                 ncc.ThongTin    = item.ThongTin;
                 ncc.BiDanh      = item.BiDanh;
                 ncc.NgayTao     = item.NgayTao;
                 ncc.NgayCapNhat = item.NgayCapNhat;
                 ListNCC.Add(ncc);
             }
             reponse = Request.CreateResponse(HttpStatusCode.OK, ListNCC);
         }
         return(reponse);
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
 public HttpResponseMessage EditNCC([FromBody] NCCDTO ncc)
 {
     try
     {
         var entity = db.NhaCungCaps.SingleOrDefault(x => x.MaNCC == ncc.MaNCC);
         if (entity == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không Tìm Thấy Nhà Cung Cấp"));
         }
         else
         {
             entity.TenNCC      = ncc.TenNCC;
             entity.ThongTin    = ncc.ThongTin;
             entity.BiDanh      = ncc.BiDanh;
             entity.LoGo        = ncc.LoGo;
             entity.NgayTao     = ncc.NgayTao;
             entity.NgayCapNhat = DateTime.Now;
             db.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, entity));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Beispiel #3
0
 public HttpResponseMessage GetMegaMenu()
 {
     try
     {
         List <LoaiSP>    entity     = db.LoaiSPs.ToList();
         List <LoaiSPDTO> listloaisp = new List <LoaiSPDTO>();
         foreach (var item in entity)
         {
             LoaiSPDTO loaisp = new LoaiSPDTO();
             loaisp.MaLoaiSP  = item.MaLoaiSP;
             loaisp.TenLoaiSP = item.TenLoaiSP;
             loaisp.MaLoaiSP  = item.MaLoaiSP;
             List <NCCDTO> listncc = new List <NCCDTO>();
             foreach (var item2 in item.SanPhams.GroupBy(x => x.NhaCungCap))
             {
                 NCCDTO ncc = new NCCDTO();
                 ncc.TenNCC = item2.Key.TenNCC;
                 ncc.MaNCC  = item2.Key.MaNCC;
                 listncc.Add(ncc);
                 loaisp.ListNCC = listncc;
             }
             listloaisp.Add(loaisp);
         }
         return(Request.CreateResponse(HttpStatusCode.OK, listloaisp));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
 public HttpResponseMessage GetAll(int page, int pagesize, string keyword)
 {
     try
     {
         int totalrows = 0;
         var entity    = db.LoaiSPs.ToList();
         if (!string.IsNullOrEmpty(keyword))
         {
             entity = db.LoaiSPs.Where(x => x.TenLoaiSP.Contains(keyword)).ToList();
         }
         if (entity == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not Found"));
         }
         else
         {
             var query = entity.OrderByDescending(x => x.NgayCapNhat).Skip(page * pagesize).Take(pagesize).ToList();
             totalrows = entity.Count();
             List <LoaiSPDTO> ListloaiSP = new List <LoaiSPDTO>();
             foreach (var item in query)
             {
                 LoaiSPDTO loaisp = new LoaiSPDTO();
                 loaisp.MaLoaiSP    = item.MaLoaiSP;
                 loaisp.TenLoaiSP   = item.TenLoaiSP;
                 loaisp.BiDanh      = item.BiDanh;
                 loaisp.NgayCapNhat = item.NgayCapNhat;
                 loaisp.NgayTao     = item.NgayTao;
                 loaisp.Total       = item.SanPhams.Count();
                 List <NCCDTO> findncc = new List <NCCDTO>();
                 foreach (var item2 in item.SanPhams.GroupBy(x => x.NhaCungCap))
                 {
                     NCCDTO ncc = new NCCDTO();
                     ncc.MaNCC  = item2.Key.MaNCC;
                     ncc.TenNCC = item2.Key.TenNCC;
                     ncc.SLSP   = item.SanPhams.Where(x => x.MaNCC == item2.Key.MaNCC).Count();
                     findncc.Add(ncc);
                     loaisp.ListNCC = findncc;
                 }
                 ListloaiSP.Add(loaisp);
             }
             var pagin = new Pager <LoaiSPDTO>()
             {
                 Item       = ListloaiSP,
                 Page       = page,
                 TotalCount = totalrows,
                 TotalPage  = (int)Math.Ceiling((decimal)totalrows / pagesize),
             };
             return(Request.CreateResponse(HttpStatusCode.OK, pagin));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Beispiel #5
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            NCCDTO NCCDTO = new NCCDTO()
            {
                ConQuanLy = true
            };
            ThemNCC frm = new ThemNCC(true, NCCDTO);

            frm.ShowDialog();

            hienThi();
        }
Beispiel #6
0
 public static void saveNCC(NCCDTO hs, string method)
 {
     SqlParameter[] sqlP = new SqlParameter[4];
     sqlP[0] = new SqlParameter("@MaNCC", hs.MaNCC1);
     sqlP[1] = new SqlParameter("@TenNCC", hs.TenNCC1);
     sqlP[2] = new SqlParameter("@DiaChi", hs.DiaChi1);
     sqlP[3] = new SqlParameter("@DienThoai", hs.DienThoai1);
     if (method == sys.INSERT)
     {
         GenericDAL.execNonQuery("sp_InsertNCC", sqlP, Conn);
     }
     else if (method == sys.UPDATE)
     {
         GenericDAL.execNonQuery("sp_UpdateNCC", sqlP, Conn);
     }
 }
Beispiel #7
0
 public ThemNCC(bool _isAddNew1, NCCDTO NCCDTO)
 {
     InitializeComponent();
     _isAddNew            = _isAddNew1;
     txtMa.Text           = NCCDTO.MaNCC;
     txtTen.Text          = NCCDTO.TenNCC;
     gluKhuVuc.EditValue  = NCCDTO.Tenkvncc;
     txtDiaChi.Text       = NCCDTO.diachiNCC;
     txtDT.Text           = NCCDTO.DTNCC;
     txtEmail.Text        = NCCDTO.EmailNCC;
     ckbConQuanLy.Checked = NCCDTO.ConQuanLy;
     if (!_isAddNew)
     {
         txtMa.Enabled = false;
     }
 }
Beispiel #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.QueryString["productid"] != null)
     {
         string id = Request.QueryString["productid"].ToString();
         _product = _QLSP.getProductById(id);
         _NCC     = _QLNCC.GeNCCbyiD(_product.Ncc);
         string idNCC = Request.QueryString["nccId"].ToString();
         RptProuct_NCC.DataSource = _QLSP.GetProductByNCC(idNCC);
         RptProuct_NCC.DataBind();
     }
     else
     {
         Response.Redirect("products.aspx");
     }
 }
 public HttpResponseMessage GetAll(int page, int pagesize, string keyword)
 {
     try
     {
         HttpResponseMessage reponse = null;
         var entity = db.NhaCungCaps.ToList();
         if (!string.IsNullOrEmpty(keyword))
         {
             entity = db.NhaCungCaps.Where(x => x.TenNCC.Contains(keyword)).ToList();
         }
         var           query     = entity.OrderByDescending(x => x.NgayCapNhat).Skip(page * pagesize).Take(pagesize);
         var           totalrows = entity.Count();
         List <NCCDTO> ListNCC   = new List <NCCDTO>();
         if (entity.Count <= 0)
         {
             reponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không Có Dữ Liệu");
         }
         else
         {
             foreach (var item in query)
             {
                 NCCDTO ncc = new NCCDTO();
                 ncc.MaNCC       = item.MaNCC;
                 ncc.TenNCC      = item.TenNCC;
                 ncc.ThongTin    = item.ThongTin;
                 ncc.BiDanh      = item.BiDanh;
                 ncc.NgayTao     = item.NgayTao;
                 ncc.NgayCapNhat = item.NgayCapNhat;
                 ListNCC.Add(ncc);
             }
             var pagin = new Pager <NCCDTO>()
             {
                 Item       = ListNCC,
                 Page       = page,
                 TotalCount = totalrows,
                 TotalPage  = (int)Math.Ceiling((decimal)totalrows / pagesize),
             };
             reponse = Request.CreateResponse(HttpStatusCode.OK, pagin);
         }
         return(reponse);
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Beispiel #10
0
        /* in form*/
        private NCCDTO checkData()
        {
            string ma     = txtMaNCC.Text;
            string ten    = txtTenNCC.Text;
            string diaChi = txtDiaChi.Text;
            string SDT    = mtbDienThoai.Text;
            string z      = string.Join("", txtMaNCC.Text.Where(char.IsDigit));

            if (txtMaNCC.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Nhập Mã KH", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaNCC.Focus();
                return(null);
            }
            else if (txtTenNCC.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Nhập Tên KH", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenNCC.Focus();
                return(null);
            }
            else if (mtbDienThoai.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Nhập SĐT", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mtbDienThoai.Focus();
                return(null);
            }
            else if (txtDiaChi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Nhập Địa Chỉ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDiaChi.Focus();
                return(null);
            }
            else if (txtMaNCC.Text.Contains("NCC") == false)
            {
                MessageBox.Show("Nhập Theo Định Dạng Là \"NCC\"", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); 
 txtMaNCC.Focus(); 
                return(null);
            }
            
            else if (z == "")
            {
                MessageBox.Show("Nhập Theo Định Dạng Là \"NCC\" và Thêm Số Đằng Sau", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); 
 txtMaNCC.Focus(); 
                return(null);
            }

            NCCDTO dto = new NCCDTO(ma, Handling.FormHandling.formatString(ten), diaChi, SDT);

            return(dto);
        }
 public HttpResponseMessage GetById([FromUri] int id)
 {
     try
     {
         var    entity = db.NhaCungCaps.Find(id);
         NCCDTO ncc    = new NCCDTO();
         ncc.MaNCC    = entity.MaNCC;
         ncc.TenNCC   = entity.TenNCC;
         ncc.ThongTin = entity.ThongTin;
         ncc.BiDanh   = entity.BiDanh;
         ncc.LoGo     = entity.LoGo;
         ncc.NgayTao  = entity.NgayTao;
         return(Request.CreateResponse(HttpStatusCode.OK, ncc));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            if (Session["Loai"] != null)
            {
                int Loai = int.Parse(Session["Loai"].ToString());

                if (Loai == 1)
                {
                    if (Session["MaNCC"] != null)
                    {
                        string Ma = Session["MaNCC"].ToString();
                        _ncc = _QLNCC.GeNCCbyiD(Ma);
                        txtProducerName.Text = _ncc.TenNCC;
                        txtAddress.Text      = _ncc.Diachi;
                        txtActiveTime.Text   = _ncc.Giohoatdong;
                        if (_ncc.Dvship == true)
                        {
                            cbShip.Checked = true;
                        }
                        else
                        {
                            cbShip.Checked = false;
                        }
                        txtMail.Text = _ncc.Mail;
                        URL.ImageUrl = _ncc.Url;
                        URL.Visible  = true;
                    }
                }
                else
                {
                    Response.Redirect("login.aspx");
                }
            }
            else
            {
                Response.Redirect("login.aspx");
            }
        }
Beispiel #13
0
        private void buttonThem_Click(object sender, EventArgs e)
        {
            if (textBoxMaNCC.TextLength == 0)
            {
                MaterialMessageBox.Show("Vui lòng nhập mã NCC", "Hướng dẫn");
                return;
            }

            NCCDTO nCC = new NCCDTO(textBoxMaNCC.Text, textBoxTenNCC.Text, multiLineTextBoxDiaChiNCC.Text, textBoxSDTNCC.Text);

            int result = NCCBUS.Instance.ThemNCC(nCC);

            if (result != 1)
            {
                MaterialMessageBox.Show("Chưa thêm được NCC " + nCC.MaNCC, "Thất bại");
                return;
            }

            LoadDSNCC();
        }
Beispiel #14
0
 public HttpResponseMessage GetAll()
 {
     try
     {
         var entity = db.LoaiSPs.ToList();
         if (entity == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not Found"));
         }
         else
         {
             List <LoaiSPDTO> ListloaiSP = new List <LoaiSPDTO>();
             foreach (var item in entity)
             {
                 LoaiSPDTO loaisp = new LoaiSPDTO();
                 loaisp.MaLoaiSP    = item.MaLoaiSP;
                 loaisp.TenLoaiSP   = item.TenLoaiSP;
                 loaisp.BiDanh      = item.BiDanh;
                 loaisp.NgayCapNhat = item.NgayCapNhat;
                 loaisp.NgayTao     = item.NgayTao;
                 loaisp.Total       = item.SanPhams.Count();
                 List <NCCDTO> findncc = new List <NCCDTO>();
                 foreach (var item2 in item.SanPhams.GroupBy(x => x.NhaCungCap))
                 {
                     NCCDTO ncc = new NCCDTO();
                     ncc.MaNCC  = item2.Key.MaNCC;
                     ncc.TenNCC = item2.Key.TenNCC;
                     ncc.SLSP   = item.SanPhams.Where(x => x.MaNCC == item2.Key.MaNCC).Count();
                     findncc.Add(ncc);
                     loaisp.ListNCC = findncc;
                 }
                 ListloaiSP.Add(loaisp);
             }
             return(Request.CreateResponse(HttpStatusCode.OK, ListloaiSP));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Beispiel #15
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     if (checkDuplicated() == 2)
     {
         MessageBox.Show("Không Có Mã Đó Để Thay Đổi Liên Quan", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         txtMaNCC.Text = "";
         return;
     }
     else
     {
         NCCDTO ob = checkData();
         if (ob != null)
         {
             B_NCC.saveNCC(ob, sys.UPDATE);
             MessageBox.Show("Sửa Thành Công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             dt = B_NCC.GetAllNCC();
             dgvNCC.DataSource = dt;
             clearTxt();
         }
     }
 }
 public HttpResponseMessage TaoMoi([FromBody] NCCDTO ncc)
 {
     try
     {
         HttpResponseMessage reponse = null;
         var entity = new NhaCungCap();
         entity.TenNCC   = ncc.TenNCC;
         entity.ThongTin = ncc.ThongTin;
         entity.BiDanh   = ncc.BiDanh;
         entity.LoGo     = ncc.LoGo;
         entity.NgayTao  = DateTime.Now;
         db.NhaCungCaps.Add(entity);
         db.SaveChanges();
         reponse = Request.CreateResponse(HttpStatusCode.OK, entity);
         return(reponse);
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Beispiel #17
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            NCCDTO ob = checkData();

            if (ob != null)
            {
                if (checkDuplicated() == 1)
                {
                    MessageBox.Show("Mã Nhà Cung Cấp Trùng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMaNCC.Focus();
                    return;
                }
                else
                {
                    B_NCC.saveNCC(ob, sys.INSERT);
                    MessageBox.Show("Thêm Thành Công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dt = B_NCC.GetAllNCC();
                    dgvNCC.DataSource = dt;
                    clearTxt();
                }
            }
        }
Beispiel #18
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            _currentRowIndex = gridView1.FocusedRowHandle;
            if (_currentRowIndex < 0)
            {
                return;
            }

            NCCDTO NCCDTO = new NCCDTO()
            {
                MaNCC     = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["MaNCC"]).ToString(),
                TenNCC    = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["TenNCC"]).ToString(),
                Tenkvncc  = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["TenKV"]).ToString(),
                diachiNCC = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["diachiNCC"]).ToString(),
                DTNCC     = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["DTNCC"]).ToString(),
                EmailNCC  = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["EmailNCC"]).ToString(),
                ConQuanLy = bool.Parse(gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["ConQuanLy"]).ToString()),
            };
            ThemNCC frm = new ThemNCC(false, NCCDTO);

            frm.ShowDialog();
            hienThi();
        }
Beispiel #19
0
 public static void saveNCC(NCCDTO hs, string method)
 {
     D_NCC.saveNCC(hs, method);
 }