コード例 #1
0
        //DeleteOB
        public bool _DeleteOb(Ob_DM_ChietKhau ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From DM_ChietKhau Where ID_ChietKhau=@ID_ChietKhau"
            };

            command.Parameters.Add(new SqlParameter("ID_ChietKhau", ob.ID_CHIETKHAU));
            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);
        }
コード例 #2
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_DM_ChietKhau ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update DM_ChietKhau Set MaChietKhau=@MaChietKhau, TenChietKhau=@TenChietKhau Where ID_ChietKhau=@ID_ChietKhau"
            };

            command.Parameters.Add("ID_ChietKhau", SqlDbType.Int).Value = ob.ID_CHIETKHAU;
            if (ob.MACHIETKHAU.Trim() == "")
            {
                command.Parameters.Add("MaChietKhau", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaChietKhau", SqlDbType.VarChar).Value = ob.MACHIETKHAU;
            }
            if (ob.TENCHIETKHAU.Trim() == "")
            {
                command.Parameters.Add("TenChietKhau", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenChietKhau", SqlDbType.NVarChar).Value = ob.TENCHIETKHAU;
            }
            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);
        }
コード例 #3
0
        //GetObWhere
        public Ob_DM_ChietKhau _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_DM_ChietKhau ob      = new Ob_DM_ChietKhau();
            SqlCommand      command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_ChietKhau, MaChietKhau, TenChietKhau From DM_ChietKhau Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CHIETKHAU = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MACHIETKHAU = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENCHIETKHAU = Convert.ToString(reader[2]);
                }
            }
            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);
        }
コード例 #4
0
        //InsertobGetId
        public int _InsertObGetId(Ob_DM_ChietKhau ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into DM_ChietKhau (MaChietKhau, TenChietKhau) Values(@MaChietKhau, @TenChietKhau)Select @@IDENTITY"
                };
                if (ob.MACHIETKHAU.Trim() == "")
                {
                    command.Parameters.Add("MaChietKhau", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaChietKhau", SqlDbType.VarChar).Value = ob.MACHIETKHAU;
                }
                if (ob.TENCHIETKHAU.Trim() == "")
                {
                    command.Parameters.Add("TenChietKhau", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenChietKhau", SqlDbType.NVarChar).Value = ob.TENCHIETKHAU;
                }
                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);
        }
コード例 #5
0
        //ListWhere_sp
        public List <Ob_DM_ChietKhau> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DM_ChietKhau> list    = new List <Ob_DM_ChietKhau>();
            SqlCommand             command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

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

            while (reader.Read())
            {
                Ob_DM_ChietKhau ob = new Ob_DM_ChietKhau();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CHIETKHAU = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MACHIETKHAU = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENCHIETKHAU = Convert.ToString(reader[2]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
コード例 #6
0
        //ListAll
        public List <Ob_DM_ChietKhau> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DM_ChietKhau> list    = new List <Ob_DM_ChietKhau>();
            SqlCommand             command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_ChietKhau, MaChietKhau, TenChietKhau From DM_ChietKhau"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DM_ChietKhau ob = new Ob_DM_ChietKhau();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CHIETKHAU = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MACHIETKHAU = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENCHIETKHAU = Convert.ToString(reader[2]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
コード例 #7
0
 public Ob_DM_ChietKhau(Ob_DM_ChietKhau newOb)
 {
     id_chietkhau = newOb.ID_CHIETKHAU;
     machietkhau  = newOb.MACHIETKHAU;
     tenchietkhau = newOb.TENCHIETKHAU;
 }