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

            command.Parameters.Add(new SqlParameter("ID_KhoangGia", ob.ID_KHOANGGIA));
            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_POS_KhuyenMaiKhoangGiaSanPham(Ob_POS_KhuyenMaiKhoangGiaSanPham newOb)
 {
     id_khoanggia = newOb.ID_KHOANGGIA;
     id_khuyenmai = newOb.ID_KHUYENMAI;
     tugiatri     = newOb.TUGIATRI;
     dengiatri    = newOb.DENGIATRI;
     giamgiapt    = newOb.GIAMGIAPT;
     giamgiatien  = newOb.GIAMGIATIEN;
     id_sanpham   = newOb.ID_SANPHAM;
     soluong      = newOb.SOLUONG;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
     createdtime  = newOb.CREATEDTIME;
     createdby    = newOb.CREATEDBY;
 }
Example #3
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_POS_KhuyenMaiKhoangGiaSanPham ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update POS_KhuyenMaiKhoangGiaSanPham Set ID_KhuyenMai=@ID_KhuyenMai, TuGiaTri=@TuGiaTri, DenGiaTri=@DenGiaTri, GiamGiaPT=@GiamGiaPT, GiamGiaTien=@GiamGiaTien, ID_SanPham=@ID_SanPham, SoLuong=@SoLuong, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy Where ID_KhoangGia=@ID_KhoangGia"
            };

            command.Parameters.Add("ID_KhoangGia", SqlDbType.BigInt).Value = ob.ID_KHOANGGIA;
            command.Parameters.Add("ID_KhuyenMai", SqlDbType.Int).Value    = ob.ID_KHUYENMAI;
            command.Parameters.Add("TuGiaTri", SqlDbType.Money).Value      = ob.TUGIATRI;
            command.Parameters.Add("DenGiaTri", SqlDbType.Money).Value     = ob.DENGIATRI;
            command.Parameters.Add("GiamGiaPT", SqlDbType.Float).Value     = ob.GIAMGIAPT;
            command.Parameters.Add("GiamGiaTien", SqlDbType.Money).Value   = ob.GIAMGIATIEN;
            command.Parameters.Add("ID_SanPham", SqlDbType.BigInt).Value   = ob.ID_SANPHAM;
            command.Parameters.Add("SoLuong", SqlDbType.Int).Value         = ob.SOLUONG;
            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);
        }
Example #4
0
        //InsertobGetId
        public int _InsertObGetId(Ob_POS_KhuyenMaiKhoangGiaSanPham ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into POS_KhuyenMaiKhoangGiaSanPham (ID_KhoangGia, ID_KhuyenMai, TuGiaTri, DenGiaTri, GiamGiaPT, GiamGiaTien, ID_SanPham, SoLuong, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy) Values(@ID_KhoangGia, @ID_KhuyenMai, @TuGiaTri, @DenGiaTri, @GiamGiaPT, @GiamGiaTien, @ID_SanPham, @SoLuong, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreatedBy)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_KhoangGia", SqlDbType.BigInt).Value = ob.ID_KHOANGGIA;
                command.Parameters.Add("ID_KhuyenMai", SqlDbType.Int).Value    = ob.ID_KHUYENMAI;
                command.Parameters.Add("TuGiaTri", SqlDbType.Money).Value      = ob.TUGIATRI;
                command.Parameters.Add("DenGiaTri", SqlDbType.Money).Value     = ob.DENGIATRI;
                command.Parameters.Add("GiamGiaPT", SqlDbType.Float).Value     = ob.GIAMGIAPT;
                command.Parameters.Add("GiamGiaTien", SqlDbType.Money).Value   = ob.GIAMGIATIEN;
                command.Parameters.Add("ID_SanPham", SqlDbType.BigInt).Value   = ob.ID_SANPHAM;
                command.Parameters.Add("SoLuong", SqlDbType.Int).Value         = ob.SOLUONG;
                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);
        }
Example #5
0
        //GetObWhere
        public Ob_POS_KhuyenMaiKhoangGiaSanPham _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_POS_KhuyenMaiKhoangGiaSanPham ob = new Ob_POS_KhuyenMaiKhoangGiaSanPham();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_KhoangGia, ID_KhuyenMai, TuGiaTri, DenGiaTri, GiamGiaPT, GiamGiaTien, ID_SanPham, SoLuong, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy From POS_KhuyenMaiKhoangGiaSanPham Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_KHOANGGIA = Convert.ToInt64(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_KHUYENMAI = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TUGIATRI = Convert.ToDouble(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.DENGIATRI = Convert.ToDouble(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.GIAMGIAPT = Convert.ToDouble(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.GIAMGIATIEN = Convert.ToDouble(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.ID_SANPHAM = Convert.ToInt64(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.SOLUONG = Convert.ToInt32(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[8]);
                }
                if (reader[9] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[9]);
                }
                if (reader[10] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[10]);
                }
                if (reader[11] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[11]);
                }
            }
            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);
        }
Example #6
0
        //ListWhere_sp
        public List <Ob_POS_KhuyenMaiKhoangGiaSanPham> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_POS_KhuyenMaiKhoangGiaSanPham> list = new List <Ob_POS_KhuyenMaiKhoangGiaSanPham>();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

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

            while (reader.Read())
            {
                Ob_POS_KhuyenMaiKhoangGiaSanPham ob = new Ob_POS_KhuyenMaiKhoangGiaSanPham();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_KHOANGGIA = Convert.ToInt64(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_KHUYENMAI = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TUGIATRI = Convert.ToDouble(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.DENGIATRI = Convert.ToDouble(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.GIAMGIAPT = Convert.ToDouble(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.GIAMGIATIEN = Convert.ToDouble(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.ID_SANPHAM = Convert.ToInt64(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.SOLUONG = Convert.ToInt32(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[8]);
                }
                if (reader[9] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[9]);
                }
                if (reader[10] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[10]);
                }
                if (reader[11] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[11]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }