public bool UpdateRow(PhieuNhapSachDTO obj) { try { if (_connection.State != ConnectionState.Open) { _connection.Open(); } string sql = "UPDATE [dbo].[PhieuNhapSach]\n" + " SET [NgayNhap] = @NgayNhap\n" + " ,[MaNhanVien] = @MaNhanVien\n" + " WHERE [MaPhieuNhapSach] = @MaPhieuNhapSach"; var cmd = new SqlCommand(sql, _connection); cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach; cmd.Parameters.Add("@NgayNhap", SqlDbType.Date).Value = obj.NgayNhap; cmd.Parameters.Add("@MaNhanVien", SqlDbType.Char).Value = obj.MaNhanVien; cmd.ExecuteNonQuery(); _connection.Close(); return(true); } catch (Exception ex) { _connection.Close(); Console.WriteLine(ex.Message); } return(false); }
public PhieuNhapSachDTO GetRow(string maPhieuNhapSach) { try { var obj = new PhieuNhapSachDTO(); if (_connection.State != ConnectionState.Open) { _connection.Open(); } SqlCommand command = new SqlCommand("SELECT * FROM PhieuNhapSach WHERE MaPhieuNhapSach = @maphieunhapsach", _connection); command.Parameters.Add("@maphieunhapsach", SqlDbType.Char).Value = maPhieuNhapSach; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { obj.MaPhieuNhapSach = reader["MaPhieuNhapSach"].ToString(); obj.MaNhanVien = reader["MaNhanVien"].ToString(); obj.NgayNhap = (DateTime)reader["NgayNhap"]; reader.Close(); } return(obj); } catch (Exception ex) { _connection.Close(); Console.WriteLine(ex.Message); } return(null); }
private void btnXoaPhieu_Click(object sender, EventArgs e) { int currentRowIndex = this.dgvDanhSachPhieuNhap.CurrentCellAddress.Y; //'current row selected //Verify that indexing OK if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachPhieuNhap.RowCount) { PhieuNhapSachDTO obj = (PhieuNhapSachDTO)dgvDanhSachPhieuNhap.Rows[currentRowIndex].DataBoundItem; this.txtMaPhieuNhap.Text = obj.MaPN; this.dtpNgayNhap.Text = obj.NgayNhap; string result = this.bus.delete(obj); if (result == "0") { MessageBox.Show("Xóa phiếu nhập thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.buildDanhSach(); return; } else { MessageBox.Show("Xóa phiếu nhập thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("Chưa chọn phiếu nhập trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK); } }
public bool AddRow(PhieuNhapSachDTO obj) { try { if (_connection.State != ConnectionState.Open) { _connection.Open(); } string sql = "INSERT INTO [dbo].[PhieuNhapSach]\n" + " ([MaPhieuNhapSach]\n" + " ,[NgayNhap]\n" + " ,[MaNhanVien])\n" + " VALUES\n" + " (@MaPhieuNhapSach\n" + " ,@NgayNhap\n" + " ,@MaNhanVien)"; SqlCommand cmd = new SqlCommand(sql, _connection); cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach; cmd.Parameters.Add("@NgayNhap", SqlDbType.Date).Value = obj.NgayNhap; cmd.Parameters.Add("@MaNhanVien", SqlDbType.Char).Value = obj.MaNhanVien; cmd.ExecuteNonQuery(); _connection.Close(); return(true); } catch (Exception ex) { _connection.Close(); Console.WriteLine(ex.Message); } return(false); }
public string delete(PhieuNhapSachDTO obj) { string query = string.Empty; query += " DELETE FROM [PHIEUNHAP] "; query += " WHERE "; query += " [MaPhieuNhap] = @MaPhieuNhap "; using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandType = CommandType.Text; comm.CommandText = query; comm.Parameters.AddWithValue("@MaPhieuNhap", obj.MaPN); try { conn.Open(); comm.ExecuteNonQuery(); } catch (Exception ex) { conn.Close(); //' xóa that bai!!! return("Xóa phiếu nhập thất bại\n" + ex.Message + "\n" + ex.StackTrace); } } } return("0"); }
public string insert(PhieuNhapSachDTO obj) { string query = string.Empty; query += "INSERT INTO [PHIEUNHAP] ([MaPhieuNhap], [NgayNhap])"; query += "VALUES (@MaPhieuNhap,@NgayNhap)"; using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandType = CommandType.Text; comm.CommandText = query; comm.Parameters.AddWithValue("@MaPhieuNhap", obj.MaPN); comm.Parameters.AddWithValue("@NgayNhap", obj.NgayNhap); try { conn.Open(); comm.ExecuteNonQuery(); } catch (Exception ex) { conn.Close(); // them that bai!!! return("Thêm ngày nhập phiếu thất bại\n" + ex.Message + "\n" + ex.StackTrace); } } } return("0"); }
public IActionResult Post([FromBody] PhieuNhapSachDTO value) { if ((_dataRepository as PhieuNhapSachDM).CheckExist(value.MaPn)) { return(Conflict()); } (_dataRepository as PhieuNhapSachDM).Add(value); return(Ok()); }
public string insert(PhieuNhapSachDTO obj) { if (obj.NgayNhap == null || obj.MaPN == string.Empty) { return("Ngày nhập hoặc mã phiếu nhập không hợp lệ"); } return(dal.insert(obj)); }
public bool AddPhieuNhap(PhieuNhapSachDTO pn) { if (!objPhieuNhap.IsRowExists(pn.MaPhieuNhapSach)) { return(objPhieuNhap.AddRow(pn)); } else { return(UpdatePhieuNhap(pn)); } }
private void btnNhapChiTiet_Click(object sender, EventArgs e) { int currentRowIndex = this.dgvDanhSachPhieuNhap.CurrentCellAddress.Y; //'current row selected //Verify that indexing OK if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachPhieuNhap.RowCount) { PhieuNhapSachDTO obj = (PhieuNhapSachDTO)dgvDanhSachPhieuNhap.Rows[currentRowIndex].DataBoundItem; this.txtMaPN.Text = obj.MaPN; //this.isThemMoi = 1; this.tcPhieuNhapSach.SelectedIndex = 1; } else { MessageBox.Show("Chưa chọn phiếu nhập trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK); } }
public bool UpdatePhieuNhap(PhieuNhapSachDTO pn) { if (objPhieuNhap.IsRowExists(pn.MaPhieuNhapSach)) { ChiTietPhieuNhapSachBus ctb = new ChiTietPhieuNhapSachBus(); foreach (string ct in ctb.GetMaCTPNList(pn.MaPhieuNhapSach)) { if (ctb.DeleteChiTietPN(ct)) { Console.WriteLine("Delete: {0}", ct); } } return(objPhieuNhap.UpdateRow(pn)); } else { return(false); } }
private void btnLapPhieu_Click(object sender, EventArgs e) { PhieuNhapSachDTO obj = new PhieuNhapSachDTO(); obj.MaPN = this.txtMaPhieuNhap.Text; //obj.NgayNhap = this.dtpNgayNhap.Text; //xem cách get ngày nhập trong c# .net nha bây obj.NgayNhap = this.dtpNgayNhap.Text; string result = this.bus.insert(obj); if (result == "0") { MessageBox.Show("Thêm mới phiếu nhập thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } else { MessageBox.Show("Thêm mới phiếu nhập thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public string selectAll(List <PhieuNhapSachDTO> lsObj) { string query = string.Empty; query += " SELECT [MaPhieuNhap], [NgayNhap]"; query += " FROM [PHIEUNHAP]"; using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandType = CommandType.Text; comm.CommandText = query; try { conn.Open(); SqlDataReader reader = comm.ExecuteReader(); if (reader.HasRows == true) { lsObj.Clear(); while (reader.Read()) { PhieuNhapSachDTO obj = new PhieuNhapSachDTO(); obj.MaPN = reader["MaPhieuNhap"].ToString(); obj.NgayNhap = reader["NgayNhap"].ToString(); lsObj.Add(obj); } } } catch (Exception ex) { conn.Close(); //' lấy that bai!!! return("Lấy phiếu nhập thất bại\n" + ex.Message + "\n" + ex.StackTrace); } } } return("0"); }
/*public string update(PhieuNhapSachDTO obj) * { * return dal.update(obj); * }*/ public string delete(PhieuNhapSachDTO obj) { return(dal.delete(obj)); }