Example #1
0
        public static bool UpdateProductInfo(SanPham sanpham)
        {
            CSQL objSQL = new CSQL(DatabaseProduct.connectionString);

            try
            {
                if (objSQL._OpenConnection() == false)
                {
                    return(false);
                }
                // input param

                SqlParameter prmID = new SqlParameter("@ID", SqlDbType.Int);
                prmID.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmID);

                SqlParameter prmTenSanPham = new SqlParameter("@Tensp", SqlDbType.NVarChar, 50);
                prmTenSanPham.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmTenSanPham);

                SqlParameter prmGia = new SqlParameter("@Gia", SqlDbType.Float);
                prmGia.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmGia);

                SqlParameter prmMoTaSP = new SqlParameter("@MoTaSP ", SqlDbType.NVarChar, 100);
                prmMoTaSP.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmMoTaSP);

                SqlParameter prmAnh = new SqlParameter("@Anh ", SqlDbType.NVarChar, 100);
                prmAnh.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmAnh);



                // output param
                SqlParameter Result = new SqlParameter("@Message", SqlDbType.NVarChar, 100);
                Result.Direction = ParameterDirection.Output;
                Result.DbType    = DbType.String;
                objSQL.Command.Parameters.Add(Result);

                //set value~
                prmID.Value         = sanpham.ID;
                prmTenSanPham.Value = sanpham.Tensp;
                prmGia.Value        = sanpham.Gia;
                prmMoTaSP.Value     = sanpham.MoTaSP;
                prmAnh.Value        = sanpham.Anh;

                objSQL.ExecuteSP("PRODUCT_UPDATE");
                if (Result.Value.ToString() == "Cập nhật thành công")
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }

            return(false);
        }
Example #2
0
        public static string Insert_Product(SanPham sanpham)
        {
            CSQL objSQL = new CSQL(DatabaseProduct.connectionString);

            try
            {
                if (objSQL._OpenConnection() == false)
                {
                    return("Open Connection false");
                }


                SqlParameter prmTenSP = new SqlParameter("@TenSP", SqlDbType.NVarChar, 50);
                prmTenSP.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmTenSP);
                // input param
                SqlParameter prmGia = new SqlParameter("@Gia", SqlDbType.Float);
                prmGia.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmGia);

                SqlParameter prmMoTaSP = new SqlParameter("@MoTaSP", SqlDbType.NVarChar, 50);
                prmMoTaSP.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmMoTaSP);

                SqlParameter prmAnh = new SqlParameter("@Anh", SqlDbType.NVarChar, 50);
                prmMoTaSP.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmAnh);


                // output param
                SqlParameter Result = new SqlParameter("@MESS", SqlDbType.NVarChar, 50);
                Result.Direction = ParameterDirection.Output;
                Result.DbType    = DbType.String;
                objSQL.Command.Parameters.Add(Result);
                prmTenSP.Value  = sanpham.Tensp;
                prmGia.Value    = sanpham.Gia;
                prmMoTaSP.Value = sanpham.MoTaSP;
                prmAnh.Value    = sanpham.Anh;

                objSQL.ExecuteSP("Tao_SanPham");
                return(Result.Value.ToString());
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }

            return("Create Product Failed");
        }
Example #3
0
        /// <summary>
        /// Nếu đăng nhập  và lấy các thông tin thành công thì return true
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        public static string User_Login(LoginViewModel User)
        {
            //Test offline

            //HttpContext.Current.Session[SessionValue.AccountType] = SessionValue.Admin;
            //return true;

            CSQL objSQL = new CSQL(DatabaseProduct.connectionString);

            try
            {
                if (objSQL._OpenConnection() == false)
                {
                    return("Không thể kết nối");
                }
                // input param

                SqlParameter prmUsername = new SqlParameter("@Username", SqlDbType.VarChar, 50);
                prmUsername.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmUsername);
                // input param
                SqlParameter prmPassword = new SqlParameter("@Password", SqlDbType.VarChar, 32);
                prmPassword.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmPassword);

                // output param
                SqlParameter Result = new SqlParameter("@MESS", SqlDbType.NChar, 50);
                Result.Direction = ParameterDirection.Output;
                Result.DbType    = DbType.String;
                objSQL.Command.Parameters.Add(Result);

                //set value~
                prmUsername.Value = User.UserName;
                prmPassword.Value = User.Password;

                objSQL.ExecuteSP("SHOP_LOGIN");
                return(Result.Value.ToString());
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }

            return("Không thể đăng nhập");
        }
Example #4
0
        public static bool DeleteProduct(int ID)
        {
            CSQL objSQL = new CSQL(DatabaseProduct.connectionString);

            try
            {
                if (objSQL._OpenConnection() == false)
                {
                    throw new Exception("Không thể kết nối");
                }

                SqlParameter prmID = new SqlParameter("@ID", SqlDbType.Int);
                prmID.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmID);
                prmID.Value = ID;

                SqlParameter Result = new SqlParameter("@Message", SqlDbType.NChar, 50);
                Result.Direction = ParameterDirection.Output;
                Result.DbType    = DbType.String;
                objSQL.Command.Parameters.Add(Result);

                if (!objSQL.ExecuteSP("DELETE_PRODUCT")) //xóa không thành công
                {
                    return(false);
                }

                if (Result.Value.ToString() == "Xóa thành công")
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }

            return(false);
        }
Example #5
0
        public static string Insert_User(Users user)
        {
            CSQL objSQL = new CSQL(DatabaseProduct.connectionString);

            try
            {
                if (objSQL._OpenConnection() == false)
                {
                    return("Open Connection false");
                }
                // input param

                SqlParameter prmUsername = new SqlParameter("@Username", SqlDbType.VarChar, 50);
                prmUsername.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmUsername);
                // input param
                SqlParameter prmPassword = new SqlParameter("@Password", SqlDbType.VarChar, 32);
                prmPassword.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmPassword);

                SqlParameter prmFullname = new SqlParameter("@FullName", SqlDbType.NVarChar, 50);
                prmUsername.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmFullname);

                SqlParameter prmEmail = new SqlParameter("@Email", SqlDbType.VarChar, 100);
                prmEmail.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmEmail);

                SqlParameter prmCCEmail = new SqlParameter("@CC", SqlDbType.VarChar, 100);
                prmCCEmail.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmCCEmail);

                SqlParameter prmPhone = new SqlParameter("@Phone", SqlDbType.NVarChar, 50);
                prmPhone.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmPhone);

                SqlParameter prmNote = new SqlParameter("@Note", SqlDbType.NVarChar, 50);
                prmNote.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmNote);

                SqlParameter prmActive = new SqlParameter("@Active", SqlDbType.Int, 50);
                prmActive.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmActive);

                SqlParameter prmRegionID = new SqlParameter("@RegionID", SqlDbType.Int, 50);
                prmRegionID.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmRegionID);

                //SqlParameter prmCompanyID = new SqlParameter("@CompanyID", SqlDbType.Int, 50);
                //prmUsername.Direction = ParameterDirection.Input;
                //objSQL.Command.Parameters.Add(prmCompanyID);

                // output param
                SqlParameter Result = new SqlParameter("@MESS", SqlDbType.NVarChar, 50);
                Result.Direction = ParameterDirection.Output;
                Result.DbType    = DbType.String;
                objSQL.Command.Parameters.Add(Result);

                //set value~
                prmUsername.Value = user.UserName;
                prmPassword.Value = user.Password.HashMD5();
                prmEmail.Value    = user.Email;
                prmCCEmail.Value  = user.CC;
                prmFullname.Value = user.FullName;
                prmPhone.Value    = user.Phone;
                prmNote.Value     = user.Note;
                prmActive.Value   = user.Active;
                prmRegionID.Value = user.RegionID;

                objSQL.ExecuteSP("CBTT_USER_CREATE");
                return(Result.Value.ToString());
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }

            return("Create User Failed");
        }