Exemple #1
0
        //DeleteOB
        public bool _DeleteOb(Ob_HT_PhienBan ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From HT_PhienBan Where ID_Phienban=@ID_Phienban"
            };

            command.Parameters.Add(new SqlParameter("ID_Phienban", ob.ID_PHIENBAN));
            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_HT_PhienBan(Ob_HT_PhienBan newOb)
 {
     id_phienban  = newOb.ID_PHIENBAN;
     ten          = newOb.TEN;
     ngayphathanh = newOb.NGAYPHATHANH;
     duongdan     = newOb.DUONGDAN;
     kichhoat     = newOb.KICHHOAT;
     ghichu       = newOb.GHICHU;
 }
Exemple #3
0
        //ListWhere_sp
        public List <Ob_HT_PhienBan> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_PhienBan> list    = new List <Ob_HT_PhienBan>();
            SqlCommand            command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

            command.Parameters.AddRange(ArrayParameter);
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_PhienBan ob = new Ob_HT_PhienBan();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_PHIENBAN = Convert.ToString(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TEN = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.NGAYPHATHANH = Convert.ToDateTime(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.DUONGDAN = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.KICHHOAT = Convert.ToBoolean(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.GHICHU = Convert.ToString(reader[5]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Exemple #4
0
        //ListAll
        public List <Ob_HT_PhienBan> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_PhienBan> list    = new List <Ob_HT_PhienBan>();
            SqlCommand            command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_Phienban, Ten, Ngayphathanh, Duongdan, Kichhoat, Ghichu From HT_PhienBan"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_PhienBan ob = new Ob_HT_PhienBan();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_PHIENBAN = Convert.ToString(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TEN = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.NGAYPHATHANH = Convert.ToDateTime(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.DUONGDAN = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.KICHHOAT = Convert.ToBoolean(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.GHICHU = Convert.ToString(reader[5]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Exemple #5
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_HT_PhienBan ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update HT_PhienBan Set Ten=@Ten, Ngayphathanh=@Ngayphathanh, Duongdan=@Duongdan, Kichhoat=@Kichhoat, Ghichu=@Ghichu Where ID_Phienban=@ID_Phienban"
            };

            if (ob.ID_PHIENBAN.Trim() == "")
            {
                command.Parameters.Add("ID_Phienban", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("ID_Phienban", SqlDbType.NVarChar).Value = ob.ID_PHIENBAN;
            }
            if (ob.TEN.Trim() == "")
            {
                command.Parameters.Add("Ten", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("Ten", SqlDbType.NVarChar).Value = ob.TEN;
            }
            if (ob.NGAYPHATHANH == DateTime.MinValue)
            {
                command.Parameters.Add("Ngayphathanh", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("Ngayphathanh", SqlDbType.DateTime).Value = ob.NGAYPHATHANH;
            }
            if (ob.DUONGDAN.Trim() == "")
            {
                command.Parameters.Add("Duongdan", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("Duongdan", SqlDbType.NVarChar).Value = ob.DUONGDAN;
            }
            command.Parameters.Add("Kichhoat", SqlDbType.Bit).Value = ob.KICHHOAT;
            if (ob.GHICHU.Trim() == "")
            {
                command.Parameters.Add("Ghichu", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("Ghichu", SqlDbType.NVarChar).Value = ob.GHICHU;
            }
            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);
        }
Exemple #6
0
        //InsertobGetId
        public int _InsertObGetId(Ob_HT_PhienBan ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into HT_PhienBan (ID_Phienban, Ten, Ngayphathanh, Duongdan, Kichhoat, Ghichu) Values(@ID_Phienban, @Ten, @Ngayphathanh, @Duongdan, @Kichhoat, @Ghichu)Select @@IDENTITY"
                };
                if (ob.ID_PHIENBAN.Trim() == "")
                {
                    command.Parameters.Add("ID_Phienban", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("ID_Phienban", SqlDbType.NVarChar).Value = ob.ID_PHIENBAN;
                }
                if (ob.TEN.Trim() == "")
                {
                    command.Parameters.Add("Ten", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("Ten", SqlDbType.NVarChar).Value = ob.TEN;
                }
                if (ob.NGAYPHATHANH == DateTime.MinValue)
                {
                    command.Parameters.Add("Ngayphathanh", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("Ngayphathanh", SqlDbType.DateTime).Value = ob.NGAYPHATHANH;
                }
                if (ob.DUONGDAN.Trim() == "")
                {
                    command.Parameters.Add("Duongdan", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("Duongdan", SqlDbType.NVarChar).Value = ob.DUONGDAN;
                }
                command.Parameters.Add("Kichhoat", SqlDbType.Bit).Value = ob.KICHHOAT;
                if (ob.GHICHU.Trim() == "")
                {
                    command.Parameters.Add("Ghichu", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("Ghichu", SqlDbType.NVarChar).Value = ob.GHICHU;
                }
                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);
        }
Exemple #7
0
        //GetObWhere
        public Ob_HT_PhienBan _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_HT_PhienBan ob      = new Ob_HT_PhienBan();
            SqlCommand     command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_Phienban, Ten, Ngayphathanh, Duongdan, Kichhoat, Ghichu From HT_PhienBan Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_PHIENBAN = Convert.ToString(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TEN = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.NGAYPHATHANH = Convert.ToDateTime(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.DUONGDAN = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.KICHHOAT = Convert.ToBoolean(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.GHICHU = Convert.ToString(reader[5]);
                }
            }
            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);
        }