Exemple #1
0
        // get SanPham for UpdateSP
        public static SanPham GetProductInfo(int ID)
        {
            CSQL objSQL = new CSQL(connectionString);

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

                SqlParameter prmId = new SqlParameter("@Id", SqlDbType.Int);
                prmId.Direction = ParameterDirection.Input;
                objSQL.Command.Parameters.Add(prmId);
                //set value~
                prmId.Value = ID;
                SqlDataReader reader = objSQL.GetDataReaderFromSP("Lay_Thongtin_SanPham");

                var currentSanPham = new SanPham();
                if (reader.Read())
                {
                    currentSanPham.ID = ID;

                    if (!reader.IsDBNull(reader.GetOrdinal("Tensp")))
                    {
                        currentSanPham.Tensp = reader.GetString(reader.GetOrdinal("Tensp"));
                    }

                    if (!reader.IsDBNull(reader.GetOrdinal("Gia")))
                    {
                        currentSanPham.Gia = reader.GetDouble(reader.GetOrdinal("Gia"));
                    }

                    if (!reader.IsDBNull(reader.GetOrdinal("MoTaSP")))
                    {
                        currentSanPham.MoTaSP = reader.GetString(reader.GetOrdinal("MoTaSP"));
                    }

                    if (!reader.IsDBNull(reader.GetOrdinal("Anh")))
                    {
                        currentSanPham.Anh = reader.GetString(reader.GetOrdinal("Anh"));
                    }

                    return(currentSanPham);
                }
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }
            finally
            {
                objSQL._CloseConnection();
            }
            return(null);
        }
Exemple #2
0
        //
        // public static string connectionString = @"Data Source=DESKTOP-A16NIVL;Initial Catalog=CBTT;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=False;";

        //create customer


        //get company list

        public static List <SanPham> Lay_DS_SanPham()
        {
            CSQL objSQL = new CSQL(connectionString);

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

                SqlDataReader reader = objSQL.GetDataReaderFromSP("Lay_DS_SanPham");

                var     DsSP = new List <SanPham>();
                SanPham sp;

                while (reader.Read())
                {
                    try          //chiennd edit 18/03/2019
                    {
                        sp = new SanPham()
                        {
                            ID     = reader.GetInt32(reader.GetOrdinal("ID")),
                            Tensp  = reader.GetString(reader.GetOrdinal("Tensp")),
                            Gia    = reader.GetDouble(reader.GetOrdinal("Gia")),
                            MoTaSP = reader.GetString(reader.GetOrdinal("MoTaSP")),
                            Anh    = reader.GetString(reader.GetOrdinal("Anh"))
                        };

                        DsSP.Add(sp);
                    }
                    catch (Exception ex) { }
                }

                return(DsSP);
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }
            finally
            {
                objSQL._CloseConnection();
            }

            return(new List <SanPham>());
        }
Exemple #3
0
        /// <summary>
        ///   Lấy Toàn bộ thông tin của User trong DataBase
        /// </summary>
        /// <param name="User">User name và pass lấy từ view</param>
        /// <returns> Users nếu là admin , hoặc customer </returns>
        public static Object GetUser(LoginViewModel User)
        {
            CSQL objSQL = new CSQL(DatabaseProduct.connectionString);

            try
            {
                if (objSQL._OpenConnection() == false)
                {
                    throw new Exception("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;

                SqlDataReader reader = objSQL.GetDataReaderFromSP("LOGIN_INFO_GET");

                //Nếu là admin thì sẽ lấy những thông tin của Addmin
                if (HttpContext.Current.Session[ApplicationConfig.AccountType] == ApplicationConfig.Admin)
                {
                    var currentUser = new Users();
                    if (reader.Read())
                    {
                        currentUser.UserName = User.UserName;
                        currentUser.Password = User.Password.HashMD5();
                        if (!reader.IsDBNull(reader.GetOrdinal("FullName")))
                        {
                            currentUser.FullName = reader.GetString(reader.GetOrdinal("FullName"));
                        }

                        currentUser.Active = reader.GetInt32(reader.GetOrdinal("Active"));
                        if (!reader.IsDBNull(reader.GetOrdinal("Phone")))
                        {
                            currentUser.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                        }

                        if (!reader.IsDBNull(reader.GetOrdinal("Email")))
                        {
                            currentUser.Email = reader.GetString(reader.GetOrdinal("Email"));
                        }

                        if (!reader.IsDBNull(reader.GetOrdinal("Note")))
                        {
                            currentUser.Note = reader.GetString(reader.GetOrdinal("Note"));
                        }

                        if (!reader.IsDBNull(reader.GetOrdinal("RegionID")))
                        {
                            currentUser.RegionID = reader.GetInt32(reader.GetOrdinal("RegionID"));
                        }

                        if (!reader.IsDBNull(reader.GetOrdinal("CreateDate")))
                        {
                            currentUser.CreateDate = reader.GetDateTime(reader.GetOrdinal("CreateDate"));
                        }

                        //                        if (!reader.IsDBNull(reader.GetOrdinal("Symbol")))
                        //                        {
                        //                            currentUser.Symbol = reader.GetString(reader.GetOrdinal("Symbol"));
                        //                        }
                        //                        if (!reader.IsDBNull(reader.GetOrdinal("Exchange")))
                        //                        {
                        //                            currentUser.Exchange = reader.GetString(reader.GetOrdinal("Exchange"));
                        //                        }

                        return(currentUser);
                    }
                }

                if (HttpContext.Current.Session[ApplicationConfig.AccountType] == ApplicationConfig.Customer)
                {
                    var currentUser = new Customer();
                    if (reader.Read())
                    {
                        currentUser.UserName = User.UserName;
                        currentUser.Password = User.Password;
                        if (!reader.IsDBNull(reader.GetOrdinal("FullName")))
                        {
                            currentUser.FullName = reader.GetString(reader.GetOrdinal("FullName"));
                        }

                        currentUser.Active = reader.GetInt32(reader.GetOrdinal("Active"));
                        if (!reader.IsDBNull(reader.GetOrdinal("Phone")))
                        {
                            currentUser.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                        }

                        if (!reader.IsDBNull(reader.GetOrdinal("Email")))
                        {
                            currentUser.Email = reader.GetString(reader.GetOrdinal("Email"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("CC")))
                        {
                            currentUser.CC = reader.GetString(reader.GetOrdinal("CC"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Note")))
                        {
                            currentUser.Note = reader.GetString(reader.GetOrdinal("Note"));
                        }

                        if (!reader.IsDBNull(reader.GetOrdinal("CompanyID")))
                        {
                            currentUser.CompanyID = reader.GetInt32(reader.GetOrdinal("CompanyID"));
                        }

                        if (!reader.IsDBNull(reader.GetOrdinal("CreateDate")))
                        {
                            currentUser.CreateDate = reader.GetDateTime(reader.GetOrdinal("CreateDate"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Symbol")))
                        {
                            currentUser.Symbol = reader.GetString(reader.GetOrdinal("Symbol"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Exchange")))
                        {
                            currentUser.Exchange = reader.GetString(reader.GetOrdinal("Exchange"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Name")))
                        {
                            currentUser.CompanyName = reader.GetString(reader.GetOrdinal("Name"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Expert")))
                        {
                            currentUser.Expert = reader.GetString(reader.GetOrdinal("Expert"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("ExpertFullName")))
                        {
                            currentUser.ExpertFullName = reader.GetString(reader.GetOrdinal("ExpertFullName"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("ExpertEmail")))
                        {
                            currentUser.ExpertEmail = reader.GetString(reader.GetOrdinal("ExpertEmail"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("ExpertPhone")))
                        {
                            currentUser.ExpertPhone = reader.GetString(reader.GetOrdinal("ExpertPhone"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("RegionID")))
                        {
                            currentUser.RegionID = reader.GetInt32(reader.GetOrdinal("RegionID"));
                        }
                        return(currentUser);
                    }
                }
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }
            finally
            {
                objSQL._CloseConnection();
            }

            return(null);
        }
Exemple #4
0
        public static List <SanPham> GetListProduct(ListProductViewModel viewModel)
        {
            CSQL objSQL = new CSQL(DatabaseProduct.connectionString);

            try
            {
                if (objSQL._OpenConnection() == false)
                {
                    throw new Exception("Không thể kết nối");
                }
                // input param
                if (viewModel.Tensp != null)
                {
                    SqlParameter prmTensp = new SqlParameter("@Tensp", SqlDbType.NVarChar, 50);
                    prmTensp.Direction = ParameterDirection.Input;
                    objSQL.Command.Parameters.Add(prmTensp);
                    prmTensp.Value = viewModel.Tensp;
                }

                SqlDataReader reader = objSQL.GetDataReaderFromSP("LIST_PRODUCT_GET");

                var     ListProduct = new List <SanPham>();
                SanPham SP;

                while (reader.Read())
                {
                    try
                    {
                        SP = new SanPham();
                        if (!reader.IsDBNull(reader.GetOrdinal("ID")))
                        {
                            SP.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Tensp")))
                        {
                            SP.Tensp = reader.GetString(reader.GetOrdinal("Tensp"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("Gia")))
                        {
                            SP.Gia = reader.GetDouble(reader.GetOrdinal("Gia"));
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("MoTaSP")))
                        {
                            SP.MoTaSP = reader.GetString(reader.GetOrdinal("MoTaSP"));
                        }

                        ListProduct.Add(SP);
                    }
                    catch (Exception ex) {
                        ex.ToString();
                    }
                }

                return(ListProduct);
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }
            finally
            {
                objSQL._CloseConnection();
            }

            return(new List <SanPham>());
        }