public ActionResult Create(NhaCC model) { ThongBaoMvc thongbao; var account = kiemtra.getUser(User.Identity.Name); var MNCC = db.NhaCCs.SingleOrDefault(s => s.MaNCC.Equals(model.MaNCC)); model.MaCN = account.MaCN; try { db.NhaCCs.Add(model); db.SaveChanges(); thongbao = new ThongBaoMvc { CssClassName = "success", Message = "Thêm nhà cung cấp thành công." }; TempData["ResultAction"] = thongbao; return(RedirectToAction("Index", "NhaCungCap")); } catch (Exception ex) { thongbao = new ThongBaoMvc { CssClassName = "danger", Message = "Lỗi." }; TempData["ResultAction"] = thongbao; log.Error("Lỗi thêm nhà cung cấp mới: " + ex.Message); return(View(model)); } }
private NhaCC LayNCCDangChon() { NhaCC ncc = new NhaCC(); ncc.MaNCC = gvNhaCungCap.GetRowCellValue(CurRowIndex, "MaNCC").ToString(); ncc.TenNCC = gvNhaCungCap.GetRowCellValue(CurRowIndex, "TenNCC").ToString(); ncc.ConQuanLy = bool.Parse(gvNhaCungCap.GetRowCellValue(CurRowIndex, "ConQuanLy").ToString()); ncc.KhuVuc = gvNhaCungCap.GetRowCellValue(CurRowIndex, "KhuVuc").ToString(); ncc.DiaChi = gvNhaCungCap.GetRowCellValue(CurRowIndex, "DiaChi").ToString(); ncc.MaSoThue = gvNhaCungCap.GetRowCellValue(CurRowIndex, "MaSoThue").ToString(); ncc.Fax = gvNhaCungCap.GetRowCellValue(CurRowIndex, "Fax").ToString(); ncc.DienThoai = gvNhaCungCap.GetRowCellValue(CurRowIndex, "DienThoai").ToString(); ncc.Mobile = gvNhaCungCap.GetRowCellValue(CurRowIndex, "Mobile").ToString(); ncc.Email = gvNhaCungCap.GetRowCellValue(CurRowIndex, "Email").ToString(); ncc.Website = gvNhaCungCap.GetRowCellValue(CurRowIndex, "Website").ToString(); ncc.TaiKhoan = gvNhaCungCap.GetRowCellValue(CurRowIndex, "TaiKhoan").ToString(); ncc.NganHang = gvNhaCungCap.GetRowCellValue(CurRowIndex, "NganHang").ToString(); ncc.GioiHanNo = int.Parse(gvNhaCungCap.GetRowCellValue(CurRowIndex, "GioiHanNo").ToString()); ncc.NoHienTai = int.Parse(gvNhaCungCap.GetRowCellValue(CurRowIndex, "NoHienTai").ToString()); ncc.ChietKhau = int.Parse(gvNhaCungCap.GetRowCellValue(CurRowIndex, "ChietKhau").ToString()); ncc.ChucVu = gvNhaCungCap.GetRowCellValue(CurRowIndex, "ChucVu").ToString(); ncc.NguoiLienHe = gvNhaCungCap.GetRowCellValue(CurRowIndex, "NguoiLienHe").ToString(); return(ncc); }
public int Delete(NhaCC ncc) { if (Load_DAL("select * from NhaCC where MaNCC='" + ncc.MaNCC + "'").Rows.Count == 0) { return(2); } else if (Load_DAL("select * from PhieuNhap where MaNCC='" + ncc.MaNCC + "'").Rows.Count > 0) { return(3); } else { SqlCommand cmd = new SqlCommand("Delete_NCC", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ma", ncc.MaNCC)); try { if (con.State != ConnectionState.Open) { con.Open(); } } catch { return(-2); } try { cmd.ExecuteNonQuery(); return(1); } catch { return(0); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } } }
public int Insert(NhaCC ncc) { if (Load_DAL("select * from NhaCC where MaNCC='" + ncc.MaNCC + "'").Rows.Count > 0) { return(2); } else { SqlCommand cmd = new SqlCommand("Insert_NCC", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ma", ncc.MaNCC)); cmd.Parameters.Add(new SqlParameter("@ten", ncc.TenNCC)); cmd.Parameters.Add(new SqlParameter("@dc", ncc.DiaChi)); cmd.Parameters.Add(new SqlParameter("@dt", ncc.DT)); cmd.Parameters.Add(new SqlParameter("@email", ncc.Email)); try { if (con.State != ConnectionState.Open) { con.Open(); } } catch { return(-2); } try { cmd.ExecuteNonQuery(); return(1); } catch { return(0); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } } }
private void btnLuu_Click(object sender, EventArgs e) { if (check == null) { NhaCC akh = new NhaCC() { MaNCC = txtMa.Text, Ten = txtTen.Text, MoTa = txtMoTa.Text, MaKV = cbKhuVuc.EditValue.ToString() }; if (BusNCC.ThemNhaCC(akh) > 0) { MessageBox.Show("Thêm thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { NhaCC akh = new NhaCC() { MaNCC = txtMa.Text, Ten = txtTen.Text, MoTa = txtMoTa.Text, MaKV = cbKhuVuc.EditValue.ToString() }; if (BusNCC.Update(akh) > 0) { MessageBox.Show("Cập nhật thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public ActionResult DeleteConfirmed(string id) { NhaCC nhaCC = db.NhaCCs.Find(id); db.NhaCCs.Remove(nhaCC); db.SaveChanges(); return(RedirectToAction("Index")); }
private void BtnLuu_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtTenNCC.Text)) { MessageBox.Show("Không được bỏ trống Tên Nhà Cung Cấp", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { NhaCC ncc = new NhaCC(); ncc.MaNCC = txtMaNCC.Text; ncc.KhuVuc = lkueKhuVuc.EditValue.ToString(); ncc.TenNCC = txtTenNCC.Text; ncc.DiaChi = txtDiaChi.Text; ncc.MaSoThue = txtMaSoThue.Text; ncc.Fax = txtFax.Text; ncc.DienThoai = txtDienThoai.Text; ncc.Mobile = txtMobile.Text; ncc.Email = txtEmail.Text; ncc.Website = txtWebsite.Text; ncc.TaiKhoan = txtTaiKhoan.Text; ncc.NganHang = txtNganHang.Text; ncc.GioiHanNo = ceGioiHanNo.EditValue != null?int.Parse(ceGioiHanNo.EditValue.ToString()) : 0; ncc.NoHienTai = 0; ncc.ChietKhau = ceChietKhau.EditValue != null?int.Parse(ceChietKhau.EditValue.ToString()) : 0; ncc.ChucVu = txtChucVu.Text; ncc.NguoiLienHe = txtNguoiLienHe.Text; ncc.ConQuanLy = cbConQuanLy.Checked; if (isInsert == true) { int kq = nv_ncc.ThemNCC(ncc); if (kq >= 1) { ThemThanhCong(); MessageBox.Show("Thêm Nhà Cung Cấp thành công"); } else { MessageBox.Show("Thêm thất bại"); } } else { int kq = nv_ncc.CapNhatNCC(ncc); if (kq >= 1) { CapNhatThanhCong(); MessageBox.Show("Cập nhật Nhà Cung Cấp thành công"); } else { MessageBox.Show("Thất bại"); } } } }
public int ThemNhaCC(NhaCC kh) { string sql = string.Format("insert into [NhaCungCap] Values('{0}', N'{1}', N'{2}', '{3}')" , kh.MaNCC, kh.Ten, kh.MoTa, kh.MaKV); var rs = db.ExecuteSQL(sql); return(rs); }
public int Update(NhaCC ncc) { string sql = string.Format("Update NhaCungCap Set Ten='{0}',MoTa='{1}',MaKhuVuc='{2}' where MaNCC='{3}'" , ncc.Ten, ncc.MoTa, ncc.MaKV, ncc.MaNCC); var rs = db.ExecuteSQL(sql); return(rs); }
public ActionResult DeleteConfirmed(int id) { NhaCC nhaCC = db.NhaCCs.FirstOrDefault(x => x.Ma == id && !x.Xoa); nhaCC.Xoa = true; db.Entry(nhaCC).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
private void btnThem_Click(object sender, EventArgs e) { MaNCC = Convert.ToInt32(txtMaNCC.Text); string TenNCC = txtTenNCC.Text; NhaCC NhaCC = new NhaCC(MaNCC, TenNCC); dtgNhaCC.DataSource = NhaCCInsert; NhaCCInsert.DataSource = nhacc.NhaCC_Insert(NhaCC); LoadNhaCC(); }
public ActionResult Edit([Bind(Include = "MaNCC,TenNCC,SDT")] NhaCC nhaCC) { if (ModelState.IsValid) { db.Entry(nhaCC).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nhaCC)); }
public int UpdateData(NhaCC NCC) { SqlParameter[] para = { new SqlParameter("MaNCC", NCC.MaNCC), new SqlParameter("TenNCC", NCC.TenNCC), new SqlParameter("DiaChi", NCC.DiaChi), new SqlParameter("SDT", NCC.SDT) }; return(conn.ExcuteSQL("Sua_NhaCC", para)); }
public ActionResult Create(NhaCC nhaCC /*[Bind(Include = "MaNCC,TenNCC,DiaChi,SDT,Email")]*/) { if (ModelState.IsValid) { nhaCC.MaNCC = autoID(); db.NhaCCs.Add(nhaCC); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public static void Them(NhaCC entity) { String sql = "INSERT INTO NhaCC( TenNhaCC) VALUES( @TenNhaCC)"; SqlCommand Command = new SqlCommand(sql, DB.Connection); Command.Parameters.AddWithValue("@MaNhaCC", entity.MaNhaCC); Command.Parameters.AddWithValue("@TenNhaCC",entity.TenNhaCC); Command.Connection.Open(); Command.ExecuteNonQuery(); Command.Connection.Close(); }
public ActionResult Create([Bind(Include = "MaNCC,TenNCC,SDT")] NhaCC nhaCC) { if (ModelState.IsValid) { db.NhaCCs.Add(nhaCC); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nhaCC)); }
private bool idHasExist(string id) { NhaCC temp = db.NhaCCs.Find(id); if (temp == null) { return(false); } return(true); }
public static void Sua(NhaCC entity) { String sql = "UPDATE NhaCC SET TenNhaCC = @TenNhaCC WHERE MaNhaCC = @MaNhaCC"; SqlCommand Command = new SqlCommand(sql, DB.Connection); Command.Parameters.AddWithValue("@MaNhaCC", entity.MaNhaCC); Command.Parameters.AddWithValue("@TenNhaCC", entity.TenNhaCC); Command.Connection.Open(); Command.ExecuteNonQuery(); Command.Connection.Close(); }
public bool NhaCc_Update(NhaCC NhaCc) { try { string query = " sp_NhaCc_Update '" + NhaCc.MaNCC + "', '" + NhaCc.TenNCC + "'"; int result = DataProvider.Instance.ExecuteNonQuery(query); return(true); } catch (Exception e) { } return(false); }
public bool Update(NhaCC entity) { var NhaCC = db.NhaCCs.Find(entity.MaNCC); NhaCC.Ten = entity.Ten; NhaCC.DiaChi = entity.DiaChi; NhaCC.SDT = entity.SDT; NhaCC.Email = entity.Email; db.SaveChanges(); return(true); }
private void BtnSua_Click(object sender, EventArgs e) { if (CurRowIndex >= 0) { NhaCC ncc = LayNCCDangChon(); frmThemNhaCungCap frmSua = new frmThemNhaCungCap(ncc); frmSua.CapNhatThanhCong += FillGridView; frmSua.CapNhatThanhCong += NhatKySua; frmSua.ShowDialog(); } }
public static void Them(NhaCC entity) { String sql = "INSERT INTO NhaCC( TenNhaCC) VALUES( @TenNhaCC)"; SqlCommand Command = new SqlCommand(sql, DB.Connection); Command.Parameters.AddWithValue("@MaNhaCC", entity.MaNhaCC); Command.Parameters.AddWithValue("@TenNhaCC", entity.TenNhaCC); Command.Connection.Open(); Command.ExecuteNonQuery(); Command.Connection.Close(); }
public bool Insert(NhaCC entity) { if (!string.IsNullOrEmpty(entity.MaNCC)) { db.NhaCCs.Add(entity); db.SaveChanges(); return(true); } else { return(false); } }
// GET: NhaCCs/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhaCC nhaCC = db.NhaCCs.Find(id); if (nhaCC == null) { return(HttpNotFound()); } return(View(nhaCC)); }
public bool DeleteNhaCC(DTO_NhaCC a) { try { NhaCC delete = db.NhaCCs.Where(p => p.MaNCC.ToString().Equals(a.MaNCC)).SingleOrDefault(); db.NhaCCs.DeleteOnSubmit(delete); db.SubmitChanges(); return(true); } catch { return(false); } }
public ActionResult Edit(int id) { if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhaCC nhaCC = db.NhaCCs.FirstOrDefault(x => x.Ma == id && !x.Xoa); if (nhaCC == null) { return(HttpNotFound()); } return(View(nhaCC)); }
private void btnLuuKb_Click(object sender, EventArgs e) { if (KTLuu()) { switch (TTLuu) { case 1: _MaNCC = txtMaNCC.Text.Trim(); var ma = dataContext.NhaCCs.Where(p => p.MaCC == (_MaNCC)).ToList(); if (ma.Count > 0) { MessageBox.Show("Mã Nhà cung cấp đã có, vui lòng nhập mã khác"); } else { NhaCC ncc = new NhaCC(); ncc.MaCC = txtMaNCC.Text.Trim(); ncc.TenCC = txtTenNCC.Text.Trim(); ncc.DiaChi = txtDiaChi.Text.Trim(); ncc.DienThoai = txtDienThoai.Text.Trim(); ncc.NguoiCC = txtNguoiCC.Text.Trim(); ncc.Status = cboStatus.SelectedIndex; dataContext.NhaCCs.Add(ncc); dataContext.SaveChanges(); enableControl(false); MessageBox.Show("Lưu thành công!"); } break; case 2: if (!string.IsNullOrEmpty(txtMaNCC.Text)) { string maNCC = txtMaNCC.Text.Trim(); NhaCC nccsua = dataContext.NhaCCs.Single(p => p.MaCC == (maNCC)); nccsua.TenCC = txtTenNCC.Text.Trim(); nccsua.DiaChi = txtDiaChi.Text.Trim(); nccsua.DienThoai = txtDienThoai.Text; nccsua.NguoiCC = txtNguoiCC.Text.Trim(); nccsua.Status = cboStatus.SelectedIndex; dataContext.SaveChanges(); MessageBox.Show("Lưu thành công!"); enableControl(false); } break; } _lNCC = dataContext.NhaCCs.OrderBy(p => p.TenCC).ToList(); grcNhaCC.DataSource = _lNCC.ToList(); } }
public frmThemNCC(NhaCC ncc) { InitializeComponent(); this.Text = "Cập Nhật Nhà Cung Cấp"; btnLuu.Text = "Cập Nhật"; txtMa.Enabled = false; check = ncc.MaNCC; txtMa.Text = ncc.MaNCC; txtTen.Text = ncc.Ten; txtMoTa.Text = ncc.MoTa; cbKhuVuc.Text = ncc.MaKV; }
private void Sua(object sender, EventArgs e) { NhaCC nh = new NhaCC() { MaNCC = gvNhaCungCap.GetRowCellValue(gvNhaCungCap.FocusedRowHandle, "Mã").ToString(), Ten = gvNhaCungCap.GetRowCellValue(gvNhaCungCap.FocusedRowHandle, "Tên").ToString(), MoTa = gvNhaCungCap.GetRowCellValue(gvNhaCungCap.FocusedRowHandle, "Mô Tả").ToString(), MaKV = gvNhaCungCap.GetRowCellValue(gvNhaCungCap.FocusedRowHandle, "Tên khu vực").ToString(), }; frmThemNCC tnh = new frmThemNCC(nh); tnh.ShowDialog(); LoadData(); }
// viết codde cho actions create(tạo mới thông tin một khách hàng) public ActionResult Create(NhaCC ncc) { //kiểm tra dữ liệu ở model if (ModelState.IsValid) { //khách hàng là dữ liệu của đối tượng khách hàng mà client gửi lên db.NhaCCs.Add(ncc); //Lưu thông tin thay đổi với database db.SaveChanges(); // Điều hướng đến trang index nếu thực hiện thành công return(RedirectToAction("Index")); } // nếu trả về view nhập thông tin khách hàng return(View()); }
public ActionResult Create([Bind(Include = "MaNCC,TenNCC,SoDienThoai")] NhaCC nhaCC) { if (ModelState.IsValid) { var ncc = new NhaCC(); ncc.TenNCC = nhaCC.TenNCC; ncc.SoDienThoai = nhaCC.SoDienThoai; db.NhaCCs.Add(nhaCC); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nhaCC)); }
public static List<NhaCC> TimTheoSql(String sql) { SqlCommand Command = new SqlCommand(sql, DB.Connection); Command.Connection.Open(); SqlDataReader Reader = Command.ExecuteReader(); var DSNCC = new List<NhaCC>(); while (Reader.Read()) { var NhaCC = new NhaCC { MaNhaCC = Convert.ToString(Reader["MaNhaCC"]), TenNhaCC = Convert.ToString(Reader["TenNhaCC"]), }; DSNCC.Add(NhaCC); } Command.Connection.Close(); return DSNCC; }
public static NhaCC Tim(String MaNhaCC) { String sql = "SELECT * FROM NhaCC WHERE MaNhaCC = @MaNhaCC"; SqlCommand Command = new SqlCommand(sql, DB.Connection); Command.Parameters.AddWithValue("@MaNhaCC", MaNhaCC); Command.Connection.Open(); SqlDataReader Reader = Command.ExecuteReader(); if (Reader.Read()) { var NhaCC = new NhaCC { MaNhaCC = Convert.ToString(Reader["MaNhaCC"]), TenNhaCC = Convert.ToString(Reader["TenNhaCC"]), }; return NhaCC; } Command.Connection.Close(); return null; }