//DeleteOB public bool _DeleteOb(Ob_KH_PhieuNXKhac_H ob, SqlConnection conn) { if (conn.ConnectionString == "") { return(false); } conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Delete From KH_PhieuNXKhac_H Where ID_NX_Khac_H=@ID_NX_Khac_H" }; command.Parameters.Add(new SqlParameter("ID_NX_Khac_H", ob.ID_NX_KHAC_H)); try { command.ExecuteNonQuery(); } catch (Exception exception) { MessageBox.Show("Không thể xóa dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(false); } command.Dispose(); command = null; conn.Close(); return(true); }
public Ob_KH_PhieuNXKhac_H(Ob_KH_PhieuNXKhac_H newOb) { id_nx_khac_h = newOb.ID_NX_KHAC_H; maphieunxkhac = newOb.MAPHIEUNXKHAC; ngaytao = newOb.NGAYTAO; id_kho = newOb.ID_KHO; id_nguoidung = newOb.ID_NGUOIDUNG; ghichu = newOb.GHICHU; id_nhaptu = newOb.ID_NHAPTU; id_loainx = newOb.ID_LOAINX; tongsoluong = newOb.TONGSOLUONG; tongtien = newOb.TONGTIEN; modifiedtime = newOb.MODIFIEDTIME; modifiedby = newOb.MODIFIEDBY; createdtime = newOb.CREATEDTIME; createdby = newOb.CREATEDBY; }
//UpdateOb ob public bool _UpdateOb(Ob_KH_PhieuNXKhac_H ob, SqlConnection conn) { if (conn.ConnectionString == "") { return(false); } conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Update KH_PhieuNXKhac_H Set ID_NX_Khac_H=@ID_NX_Khac_H, MaPhieuNXKhac=@MaPhieuNXKhac, NgayTao=@NgayTao, ID_Kho=@ID_Kho, ID_NguoiDung=@ID_NguoiDung, GhiChu=@GhiChu, ID_Nhaptu=@ID_Nhaptu, ID_LoaiNX=@ID_LoaiNX, TongSoLuong=@TongSoLuong, TongTien=@TongTien, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy Where ID_NX_Khac_H=@ID_NX_Khac_H" }; if (ob.ID_NX_KHAC_H.Trim() == "") { command.Parameters.Add("ID_NX_Khac_H", SqlDbType.UniqueIdentifier).Value = DBNull.Value; } else { command.Parameters.Add("ID_NX_Khac_H", SqlDbType.UniqueIdentifier).Value = new SqlGuid(ob.ID_NX_KHAC_H); } if (ob.MAPHIEUNXKHAC.Trim() == "") { command.Parameters.Add("MaPhieuNXKhac", SqlDbType.VarChar).Value = DBNull.Value; } else { command.Parameters.Add("MaPhieuNXKhac", SqlDbType.VarChar).Value = ob.MAPHIEUNXKHAC; } if (ob.NGAYTAO == DateTime.MinValue) { command.Parameters.Add("NgayTao", SqlDbType.DateTime).Value = DBNull.Value; } else { command.Parameters.Add("NgayTao", SqlDbType.DateTime).Value = ob.NGAYTAO; } command.Parameters.Add("ID_Kho", SqlDbType.Int).Value = ob.ID_KHO; command.Parameters.Add("ID_NguoiDung", SqlDbType.Int).Value = ob.ID_NGUOIDUNG; if (ob.GHICHU.Trim() == "") { command.Parameters.Add("GhiChu", SqlDbType.NVarChar).Value = DBNull.Value; } else { command.Parameters.Add("GhiChu", SqlDbType.NVarChar).Value = ob.GHICHU; } command.Parameters.Add("ID_Nhaptu", SqlDbType.Int).Value = ob.ID_NHAPTU; command.Parameters.Add("ID_LoaiNX", SqlDbType.Int).Value = ob.ID_LOAINX; command.Parameters.Add("TongSoLuong", SqlDbType.Int).Value = ob.TONGSOLUONG; command.Parameters.Add("TongTien", SqlDbType.Money).Value = ob.TONGTIEN; if (ob.MODIFIEDTIME == DateTime.MinValue) { command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = DBNull.Value; } else { command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = ob.MODIFIEDTIME; } if (ob.MODIFIEDBY.Trim() == "") { command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = DBNull.Value; } else { command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = ob.MODIFIEDBY; } if (ob.CREATEDTIME == DateTime.MinValue) { command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = DBNull.Value; } else { command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = ob.CREATEDTIME; } if (ob.CREATEDBY.Trim() == "") { command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = DBNull.Value; } else { command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = ob.CREATEDBY; } try { command.ExecuteNonQuery(); } catch (Exception exception) { MessageBox.Show("Không thể cập nhật dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(false); } if (command.ExecuteNonQuery() == 0) { MessageBox.Show("Không thể cập nhật dữ liệu. \r\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(false); } command.Dispose(); command = null; conn.Close(); return(true); }
//InsertobGetId public int _InsertObGetId(Ob_KH_PhieuNXKhac_H ob, SqlConnection conn) { int num = 0; if (conn.ConnectionString != "") { conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Insert Into KH_PhieuNXKhac_H (ID_NX_Khac_H, MaPhieuNXKhac, NgayTao, ID_Kho, ID_NguoiDung, GhiChu, ID_Nhaptu, ID_LoaiNX, TongSoLuong, TongTien, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy) Values(@ID_NX_Khac_H, @MaPhieuNXKhac, @NgayTao, @ID_Kho, @ID_NguoiDung, @GhiChu, @ID_Nhaptu, @ID_LoaiNX, @TongSoLuong, @TongTien, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreatedBy)Select @@IDENTITY" }; if (ob.ID_NX_KHAC_H.Trim() == "") { command.Parameters.Add("ID_NX_Khac_H", SqlDbType.UniqueIdentifier).Value = DBNull.Value; } else { command.Parameters.Add("ID_NX_Khac_H", SqlDbType.UniqueIdentifier).Value = new SqlGuid(ob.ID_NX_KHAC_H); } if (ob.MAPHIEUNXKHAC.Trim() == "") { command.Parameters.Add("MaPhieuNXKhac", SqlDbType.VarChar).Value = DBNull.Value; } else { command.Parameters.Add("MaPhieuNXKhac", SqlDbType.VarChar).Value = ob.MAPHIEUNXKHAC; } if (ob.NGAYTAO == DateTime.MinValue) { command.Parameters.Add("NgayTao", SqlDbType.DateTime).Value = DBNull.Value; } else { command.Parameters.Add("NgayTao", SqlDbType.DateTime).Value = ob.NGAYTAO; } command.Parameters.Add("ID_Kho", SqlDbType.Int).Value = ob.ID_KHO; command.Parameters.Add("ID_NguoiDung", SqlDbType.Int).Value = ob.ID_NGUOIDUNG; if (ob.GHICHU.Trim() == "") { command.Parameters.Add("GhiChu", SqlDbType.NVarChar).Value = DBNull.Value; } else { command.Parameters.Add("GhiChu", SqlDbType.NVarChar).Value = ob.GHICHU; } command.Parameters.Add("ID_Nhaptu", SqlDbType.Int).Value = ob.ID_NHAPTU; command.Parameters.Add("ID_LoaiNX", SqlDbType.Int).Value = ob.ID_LOAINX; command.Parameters.Add("TongSoLuong", SqlDbType.Int).Value = ob.TONGSOLUONG; command.Parameters.Add("TongTien", SqlDbType.Money).Value = ob.TONGTIEN; if (ob.MODIFIEDTIME == DateTime.MinValue) { command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = DBNull.Value; } else { command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = ob.MODIFIEDTIME; } if (ob.MODIFIEDBY.Trim() == "") { command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = DBNull.Value; } else { command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = ob.MODIFIEDBY; } if (ob.CREATEDTIME == DateTime.MinValue) { command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = DBNull.Value; } else { command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = ob.CREATEDTIME; } if (ob.CREATEDBY.Trim() == "") { command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = DBNull.Value; } else { command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = ob.CREATEDBY; } try { num = Convert.ToInt32(command.ExecuteScalar()); } catch (Exception exception) { MessageBox.Show("Không thể thêm dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(num); } command.Dispose(); command = null; conn.Close(); } return(num); }
//GetObWhere public Ob_KH_PhieuNXKhac_H _GetObWhere(string keyword, SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); Ob_KH_PhieuNXKhac_H ob = new Ob_KH_PhieuNXKhac_H(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Select ID_NX_Khac_H, MaPhieuNXKhac, NgayTao, ID_Kho, ID_NguoiDung, GhiChu, ID_Nhaptu, ID_LoaiNX, TongSoLuong, TongTien, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy From KH_PhieuNXKhac_H Where " + keyword + "" }; SqlDataReader reader = command.ExecuteReader(); int num = 0; while (reader.Read()) { num++; if (reader[0] != DBNull.Value) { ob.ID_NX_KHAC_H = Convert.ToString(reader[0]); } if (reader[1] != DBNull.Value) { ob.MAPHIEUNXKHAC = Convert.ToString(reader[1]); } if (reader[2] != DBNull.Value) { ob.NGAYTAO = Convert.ToDateTime(reader[2]); } if (reader[3] != DBNull.Value) { ob.ID_KHO = Convert.ToInt32(reader[3]); } if (reader[4] != DBNull.Value) { ob.ID_NGUOIDUNG = Convert.ToInt32(reader[4]); } if (reader[5] != DBNull.Value) { ob.GHICHU = Convert.ToString(reader[5]); } if (reader[6] != DBNull.Value) { ob.ID_NHAPTU = Convert.ToInt32(reader[6]); } if (reader[7] != DBNull.Value) { ob.ID_LOAINX = Convert.ToInt32(reader[7]); } if (reader[8] != DBNull.Value) { ob.TONGSOLUONG = Convert.ToInt32(reader[8]); } if (reader[9] != DBNull.Value) { ob.TONGTIEN = Convert.ToDecimal(reader[9]); } if (reader[10] != DBNull.Value) { ob.MODIFIEDTIME = Convert.ToDateTime(reader[10]); } if (reader[11] != DBNull.Value) { ob.MODIFIEDBY = Convert.ToString(reader[11]); } if (reader[12] != DBNull.Value) { ob.CREATEDTIME = Convert.ToDateTime(reader[12]); } if (reader[13] != DBNull.Value) { ob.CREATEDBY = Convert.ToString(reader[13]); } } if (num == 0) { command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(null); } command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(ob); }
//ListWhere_sp public List <Ob_KH_PhieuNXKhac_H> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); List <Ob_KH_PhieuNXKhac_H> list = new List <Ob_KH_PhieuNXKhac_H>(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = StoredName }; command.Parameters.AddRange(ArrayParameter); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Ob_KH_PhieuNXKhac_H ob = new Ob_KH_PhieuNXKhac_H(); if (reader[0] != DBNull.Value) { ob.ID_NX_KHAC_H = Convert.ToString(reader[0]); } if (reader[1] != DBNull.Value) { ob.MAPHIEUNXKHAC = Convert.ToString(reader[1]); } if (reader[2] != DBNull.Value) { ob.NGAYTAO = Convert.ToDateTime(reader[2]); } if (reader[3] != DBNull.Value) { ob.ID_KHO = Convert.ToInt32(reader[3]); } if (reader[4] != DBNull.Value) { ob.ID_NGUOIDUNG = Convert.ToInt32(reader[4]); } if (reader[5] != DBNull.Value) { ob.GHICHU = Convert.ToString(reader[5]); } if (reader[6] != DBNull.Value) { ob.ID_NHAPTU = Convert.ToInt32(reader[6]); } if (reader[7] != DBNull.Value) { ob.ID_LOAINX = Convert.ToInt32(reader[7]); } if (reader[8] != DBNull.Value) { ob.TONGSOLUONG = Convert.ToInt32(reader[8]); } if (reader[9] != DBNull.Value) { ob.TONGTIEN = Convert.ToDecimal(reader[9]); } if (reader[10] != DBNull.Value) { ob.MODIFIEDTIME = Convert.ToDateTime(reader[10]); } if (reader[11] != DBNull.Value) { ob.MODIFIEDBY = Convert.ToString(reader[11]); } if (reader[12] != DBNull.Value) { ob.CREATEDTIME = Convert.ToDateTime(reader[12]); } if (reader[13] != DBNull.Value) { ob.CREATEDBY = Convert.ToString(reader[13]); } list.Add(ob); } command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(list); }