Esempio n. 1
0
        public async Task <IActionResult> PostNhacungcap([FromBody] Nhacungcap nhacungcap)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Nhacungcap.Add(nhacungcap);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (NhacungcapExists(nhacungcap.Mancc))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetNhacungcap", new { id = nhacungcap.Mancc }, nhacungcap));
        }
        public static List <Nhacungcap> ViewAll()
        {
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
            conn.Open();
            SqlCommand sc = new SqlCommand("Nhacungcap_ProcViewAll", conn);

            sc.CommandType = CommandType.StoredProcedure;
            SqlDataReader     reader = sc.ExecuteReader();
            List <Nhacungcap> lstNcc = new List <Nhacungcap>();

            while (reader.Read())
            {
                Nhacungcap ncc = new Nhacungcap();
                ncc.NhacungcapID  = (reader["NhacungcapID"] != null ? int.Parse(reader["NhacungcapID"].ToString()) : 0);
                ncc.Tennhacungcap = (reader["Tennhacungcap"] != null ? reader["Tennhacungcap"].ToString() : "");
                ncc.Diachi        = (reader["Diachi"] != null ? reader["Diachi"].ToString() : "");
                ncc.Dienthoai     = (reader["Dienthoai"] != null ? reader["Dienthoai"].ToString() : "");
                lstNcc.Add(ncc);
            }
            reader.Close();
            conn.Close();
            return(lstNcc);
        }
Esempio n. 3
0
        public async Task <IActionResult> PutNhacungcap([FromRoute] string id, [FromBody] Nhacungcap nhacungcap)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != nhacungcap.Mancc)
            {
                return(BadRequest());
            }

            _context.Entry(nhacungcap).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NhacungcapExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void Remove(int?Id)
        {
            Nhacungcap res = db.Nhacungcap.Find(Id);

            db.Nhacungcap.Remove(res);
            db.SaveChanges();
        }
        public ActionResult DeleteConfirmed(string id)
        {
            Nhacungcap nhacungcap = db.Nhacungcaps.Find(id);

            db.Nhacungcaps.Remove(nhacungcap);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public IActionResult Create(Nhacungcap _NhaCungCap)
 {
     if (ModelState.IsValid)
     {
         INhaCungCap.Add(_NhaCungCap);
         return(RedirectToAction("Index"));
     }
     return(View(_NhaCungCap));
 }
Esempio n. 7
0
        private void CbbNCC_EditValueChanged(object sender, EventArgs e)
        {
            Nhacungcap nhacungcap = laykhachang();

            txtdiachi.Text    = nhacungcap.DiaChi;
            txtdienthoai.Text = nhacungcap.DienThoai.ToString();
            txtMancc.Text     = nhacungcap.Id.ToString();
            txttwebsite.Text  = nhacungcap.Website;
        }
        public void Update(Nhacungcap _NhaCungCap)
        {
            Nhacungcap res = db.Nhacungcap.Find(_NhaCungCap.Id);

            res.Sdt    = _NhaCungCap.Sdt;
            res.Ten    = _NhaCungCap.Ten;
            res.Diachi = _NhaCungCap.Diachi;
            db.SaveChanges();
        }
        private Nhacungcap Laythongtinncc()
        {
            Nhacungcap ncc = new Nhacungcap();

            ncc.TenNCC    = txtncc.Text;
            ncc.DiaChi    = txtdiachincc.Text.ToString();
            ncc.DienThoai = long.Parse(txtsdtncc.Text);
            ncc.Website   = txtwebsitencc.Text;
            return(ncc);
        }
 public ActionResult Edit([Bind(Include = "MaNCC,TenNCC,Diachi,Sodienthoai")] Nhacungcap nhacungcap)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nhacungcap).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nhacungcap));
 }
Esempio n. 11
0
        private void CbbNcc_EditValueChanged(object sender, EventArgs e)
        {
            Nhacungcap nhacungcap = layNcc();

            txtdiachi.Text      = nhacungcap.DiaChi;
            txtmancc.Text       = nhacungcap.Id.ToString();
            txtsodienthoai.Text = nhacungcap.DienThoai.ToString();
            txtwebsite.Text     = nhacungcap.Website;
            LoaditemID(nhacungcap.Id);
        }
Esempio n. 12
0
 public Themsunhacungcap(Nhacungcap nhacungcap)
 {
     InitializeComponent();
     Id = nhacungcap.Id;
     txtdiachincc.Text  = nhacungcap.DiaChi;
     txtncc.Text        = nhacungcap.TenNCC;
     txtwebsitencc.Text = nhacungcap.Website;
     txtsdtncc.Text     = nhacungcap.DienThoai.ToString();
     btnluu.Text        = "Cập nhật ";
     this.Text          = "Cập nhật ";
 }
        public ActionResult Create([Bind(Include = "MaNCC,TenNCC,Diachi,Sodienthoai")] Nhacungcap nhacungcap)
        {
            if (ModelState.IsValid)
            {
                db.Nhacungcaps.Add(nhacungcap);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(nhacungcap));
        }
 public IActionResult Delete(int?id)
 {
     if (id == null)
     {
         return(NotFound());
     }
     else
     {
         Nhacungcap model = INhaCungCap.GetNhacungcap(id);
         return(View(model));
     }
 }
Esempio n. 15
0
        public List <Nhacungcap> LoadNhacungcapList()
        {
            List <Nhacungcap> nccList = new List <Nhacungcap>();
            DataTable         data    = QLNhacungcapDAL.Instance.LoadNhacungcapList();

            foreach (DataRow item in data.Rows)
            {
                Nhacungcap ib = new Nhacungcap(item);
                nccList.Add(ib);
            }
            return(nccList);
        }
Esempio n. 16
0
        public Nhacungcap laykhachang()
        {
            Nhacungcap nhacungcap = new Nhacungcap();

            for (int i = 0; i < lstNCC.Count; i++)
            {
                if (lstNCC[i].Id == int.Parse(cbbNCC.EditValue.ToString()))
                {
                    nhacungcap = lstNCC[i];
                }
            }
            return(nhacungcap);
        }
        public NhacungcapCollection()
        {
            DataTable dt = DataAccess.ViewForGridView("Nhacungcap_ViewAll");

            foreach (DataRow dr in dt.Rows)
            {
                Nhacungcap ncc = new Nhacungcap();
                ncc.NhacungcapID  = int.Parse(dr["NhacungcapID"].ToString());
                ncc.Tennhacungcap = dr["Tennhacungcap"].ToString();
                ncc.Diachi        = dr["Diachi"].ToString();
                ncc.Dienthoai     = dr["Dienthoai"].ToString();
                lst.Add(ncc);
            }
        }
        // GET: Nhacungcaps/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Nhacungcap nhacungcap = db.Nhacungcaps.Find(id);

            if (nhacungcap == null)
            {
                return(HttpNotFound());
            }
            return(View(nhacungcap));
        }
Esempio n. 19
0
        public int themsuancc(int Id, Nhacungcap Nhacungcap)
        {
            string sql = "";

            if (Id != 0)
            {
                sql = string.Format("Update Nhacungcap Set TenNCC=N'{0}',DiaChi= N'{1}',DienThoai='{2}',Website='{3}' Where Id='{4}'", Nhacungcap.TenNCC, Nhacungcap.DiaChi, Nhacungcap.DienThoai, Nhacungcap.Website, Id);
            }
            else
            {
                sql = string.Format("Insert into Nhacungcap(TenNCC,DiaChi,DienThoai,Website) Values(N'{0}',N'{1}','{2}','N{3}')", Nhacungcap.TenNCC, Nhacungcap.DiaChi, Nhacungcap.DienThoai, Nhacungcap.Website);
            }
            var rs = db.thesuadulieu(sql);

            return(rs);
        }
Esempio n. 20
0
        private void bbtDanhsachncc_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form frm = this.Kiemtratontai(typeof(Nhacungcap));

            if (frm != null)
            {
                frm.Activate();
            }
            else
            {
                Nhacungcap ncc = new Nhacungcap();
                ncc.MdiParent = this;
                //dmk.StartPosition = FormStartPosition.CenterParent;
                ncc.WindowState = FormWindowState.Maximized;
                ncc.Show();
            }
        }
Esempio n. 21
0
        private void Btnsua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Object     id         = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Id");
            Object     tenNCC     = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TenNCC");
            Object     diaChi     = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DiaChi");
            Object     Ddienthoai = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DienThoai");
            Object     website    = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Website");
            Nhacungcap nhacungcap = new Nhacungcap()
            {
                Id        = int.Parse(id.ToString()),
                TenNCC    = tenNCC.ToString(),
                DiaChi    = diaChi.ToString(),
                DienThoai = long.Parse(Ddienthoai.ToString()),
                Website   = website.ToString(),
            };
            Themsunhacungcap themsuancc = new Themsunhacungcap(nhacungcap);

            themsuancc.Show();
            themsuancc.khicapnhat += Themsuancc_khicapnhat;
        }
Esempio n. 22
0
        private Models.SanPham GetData()
        {
            Models.SanPham sp = new Models.SanPham();
            int            id;

            if (int.TryParse(textBox2.Text, out id))
            {
                sp.SanphamID = id;
            }
            LoaiSanPham lsp = lstLoaisanpham.Items.Find(x => x.Tenloaisanpham == comboBox3.SelectedItem.ToString());
            Nhacungcap  ncc = lstNhacungcap.Items.Find(x => x.Tennhacungcap == comboBox4.SelectedItem.ToString());

            sp.LoaisanphamID = lsp.LoaisanphamID;
            sp.NhacungcapID  = ncc.NhacungcapID;
            sp.Tensanpham    = textBox4.Text;
            sp.Donvitinh     = textBox6.Text;
            sp.Giaban        = double.Parse(textBox7.Text);
            sp.Soluong       = int.Parse(textBox8.Text);
            return(sp);
        }
        public async Task <ActionResult <Nhacungcap> > PostNhacungcap(Nhacungcap nhacungcap)
        {
            _context.Nhacungcaps.Add(nhacungcap);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (NhacungcapExists(nhacungcap.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetNhacungcap", new { id = nhacungcap.Id }, nhacungcap));
        }
Esempio n. 24
0
        private void Btnluu_Click(object sender, EventArgs e)
        {
            Nhacungcap ncc = Laythongtinncc();
            var        row = nhacungcapBUS.themsuancc(Id, ncc);

            if (row > 0)
            {
                khicapnhat();
                if (Id != 0)
                {
                    MessageBox.Show("Cập nhật thành công!");
                }
                else
                {
                    MessageBox.Show("Thêm nhà cung cấp thành công!");
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Cập nhật thất bại!");
            }
        }
        public IActionResult Edit(int?Id)
        {
            Nhacungcap res = INhaCungCap.GetNhacungcap(Id);

            return(View(res));
        }
Esempio n. 26
0
 public int themsuancc(int Id, Nhacungcap Nhacungcap)
 {
     return(nhacungcapDAO.themsuancc(Id, Nhacungcap));
 }
Esempio n. 27
0
        /// <summary>
        /// Nút lưu trữ
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                int id     = int.Parse(textBox1.Text);
                var query1 = db.Hoadonnhapthuocs.Where(x => x.HoadonnhapthuocID == id).ToArray();
                if (query1.Length == 0)
                {
                    var        query2 = db.Nhacungcaps.Where(x => x.Tennhacungcap == textBox4.Text).ToArray();
                    Nhacungcap ncc;
                    if (query2.Length == 0)
                    {
                        ncc = new Nhacungcap()
                        {
                            Tennhacungcap = textBox4.Text
                        };
                        db.Nhacungcaps.Add(ncc);
                    }
                    else
                    {
                        ncc = query2[0];
                    }
                    Hoadonnhapthuoc hdnt = new Hoadonnhapthuoc();
                    hdnt.Ngayviet          = dateTimePicker3.Value.Date;
                    hdnt.NhanvienID        = acc.Nhanviens.ToList()[0].NhanvienID;
                    hdnt.NhacungcapID      = ncc.NhacungcapID;
                    hdnt.HoadonnhapthuocID = id;
                    float?thanhtien = 0;
                    Thuocs.ForEach(x => { thanhtien += x.Dongia * x.Soluong; });
                    hdnt.Thanhtien = thanhtien;

                    db.Hoadonnhapthuocs.Add(hdnt);

                    CTHoadonnhapthuoc ct;
                    Thuocs.ForEach(x =>
                    {
                        if (x.ThuocID == 0)
                        {
                            db.Thuocs.Add(x);
                        }
                        else
                        {
                            var t             = db.Thuocs.Where(y => y.ThuocID == x.ThuocID).ToList()[0];
                            t.Soluong        += x.Soluong;
                            db.Entry(t).State = System.Data.Entity.EntityState.Modified;
                        }
                        ct = new CTHoadonnhapthuoc();
                        ct.HoadonnhapthuocID = hdnt.HoadonnhapthuocID;
                        ct.ThuocID           = x.ThuocID;
                        ct.Soluong           = x.Soluong;
                        ct.Dongia            = x.Dongia;

                        db.CTHoadonnhapthuocs.Add(ct);
                    });
                    db.SaveChanges();
                    MessageBox.Show("Thêm thành công!");
                    reset_View();
                }
                else
                {
                    MessageBox.Show("Số hóa đơn đã tồn tại!");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Bạn đã điền thông tin hóa đơn nhập hàng sai. Hãy kiểm tra lại!");
            }
        }
        public Nhacungcap GetNhacungcap(int?Id)
        {
            Nhacungcap res = db.Nhacungcap.Find(Id);

            return(res);
        }
 public IActionResult Edit(Nhacungcap _NhaCungCap)
 {
     INhaCungCap.Update(_NhaCungCap);
     return(RedirectToAction("Index"));
 }
 public void Add(Nhacungcap _NhaCungCap)
 {
     db.Nhacungcap.Add(_NhaCungCap);
     db.SaveChanges();
 }