Exemplo n.º 1
0
        public bool CreateNews(NewsModels news, SysUserModels userSession)
        {
            if (news.newsImageFile != null && !StringUtils.IsEmpty(news.newsImageFile.FileName))
            {
                news.newsImageName = news.newsImageFile.FileName;
                news.newsImage = new byte[news.newsImageFile.InputStream.Length];
                long bytesRead = news.newsImageFile.InputStream.Read(news.newsImage, 0, (int)news.newsImageFile.InputStream.Length);
                news.newsImageFile.InputStream.Close();
            }
            news.newsCode = Utils.UtilsDAO.GenerateCode(Constants.CodePrefix.NewNews);
            news.postedBy = userSession.userCode;
            news.createdBy = userSession.userCode;
            news.updatedBy = userSession.userCode;
            news.newsStatus = Constants.Status.Active;
            news.newsType = Constants.Type.Public;
            news.newsContent = HttpUtility.HtmlDecode(news.newsContent);
            news.localeID = Constants.Language.Vietnamese;
            mapper.Insert("New.insertNews", news);

            // insert other languages
            NewsModels enNews = TranslateUtils.TranslateNews(news, Constants.Language.English);
            mapper.Insert("New.insertNews", enNews);

            NewsModels ruNews = TranslateUtils.TranslateNews(news, Constants.Language.Russian);
            mapper.Insert("New.insertNews", ruNews);

            NewsModels chNews = TranslateUtils.TranslateNews(news, Constants.Language.Chinese);
            mapper.Insert("New.insertNews", chNews);
            return true;
        }
Exemplo n.º 2
0
 public bool AdminUserLogin(SysUserLoginModels loginUser, out SysUserModels user)
 {
     user = mapper.QueryForObject<SysUserModels>("Sys.getUser", loginUser.userCode);
     if (user == null || !MD5Utils.VerifyMd5Hash(loginUser.password, user.userPassword) || !user.userType.Equals(Constants.Type.Admin))
     {
         loginUser.errorMessage = Resource.MsgLoginFailed;
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
        public void updateNews(NewsModels news, SysUserModels userSession)
        {
            if (news.newsImageFile != null && !StringUtils.IsEmpty(news.newsImageFile.FileName))
            {
                news.newsImageName = news.newsImageFile.FileName;
                news.newsImage = new byte[news.newsImageFile.InputStream.Length];
                long bytesRead = news.newsImageFile.InputStream.Read(news.newsImage, 0, (int)news.newsImageFile.InputStream.Length);
                news.newsImageFile.InputStream.Close();
            }

            news.postedBy = userSession.userCode;
            news.createdBy = userSession.userCode;
            news.updatedBy = userSession.userCode;
            news.newsStatus = Constants.Status.Active;
            news.newsType = Constants.Type.Public;
            news.newsContent = HttpUtility.HtmlDecode(news.newsContent);
            news.localeID = Constants.Language.Vietnamese;
            mapper.Update("New.updateNews", news);

            NewsModels oldNews = this.getNews(news.newsCode, Constants.Language.Vietnamese);
            // update other languages
            if (news.newsImageFile == null || StringUtils.IsEmpty(news.newsImageFile.FileName))
            {
                news.newsImageName = oldNews.newsImageName;
                news.newsImage = oldNews.newsImage;
            }
            news.postedDate = oldNews.postedDate;
            NewsModels enNews = TranslateUtils.TranslateNews(news, Constants.Language.English);
            if (this.getNews(enNews.newsCode, Constants.Language.English) != null)
            {
                mapper.Update("New.updateNews", enNews);
            }
            else
            {
                mapper.Insert("New.insertNews", enNews);
            }

            NewsModels ruNews = TranslateUtils.TranslateNews(news, Constants.Language.Russian);
            if (this.getNews(ruNews.newsCode, Constants.Language.Russian) != null)
            {
                mapper.Update("New.updateNews", ruNews);
            }
            else
            {
                mapper.Insert("New.insertNews", ruNews);
            }

            NewsModels chNews = TranslateUtils.TranslateNews(news, Constants.Language.Chinese);
            if (this.getNews(chNews.newsCode, Constants.Language.Chinese) != null)
            {
                mapper.Update("New.updateNews", chNews);
            }
            else
            {
                mapper.Insert("New.insertNews", chNews);
            }
        }
Exemplo n.º 4
0
        public SysUserProfileModels GetUserProfile(SysUserModels user)
        {
            SysUserProfileModels result = new SysUserProfileModels();
            result.birthDateList = DateUtils.genDateList();
            result.birthMonthList = DateUtils.genMonthList();
            result.birthYearList = DateUtils.genYearList();

            if (user.birthday.Day < 10)
            {
                result.birthDate = "0" + user.birthday.Date.Day.ToString();
            }
            else
            {
                result.birthDate = user.birthday.Date.Day.ToString();
            }

            if (user.birthday.Month < 10)
            {
                result.birthMonth = "0" + user.birthday.Date.Month.ToString();
            }
            else
            {
                result.birthMonth = user.birthday.Date.Month.ToString();
            }

            result.birthYear = user.birthday.Year.ToString();

            result.emailAddress = user.emailAddress;
            result.fullName = user.fullName;
            result.phoneNo = user.phoneNo;
            result.sex = user.sex;
            result.userCode = user.userCode;

            return result;
        }
Exemplo n.º 5
0
 public bool NormalUserLogin(SysUserLoginModels loginUser, out SysUserModels user)
 {
     user = mapper.QueryForObject<SysUserModels>("Sys.getUser", loginUser.userCode);
     if (user == null || !MD5Utils.VerifyMd5Hash(loginUser.password, user.userPassword) || !user.userType.Equals(Constants.Type.NO))
     {
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
        private void SaveMoney(IdxIndexModels index, SysUserModels userSession)
        {
            // Check exist index

            IDictionary<string, object> param = new Dictionary<string, object>();
            string timeFormat = Resource.DateFormat;
            string displayTimeFormat = Resource.DateFormat;
            Int32 precision = Int32.Parse(Resource.Precision);

            MstIndexTypeDAO indexTypeDAO = new MstIndexTypeDAO(this.mapper);

            MstIndexTypeModels indexTypeModel = indexTypeDAO.GetIndexType(index.indexTypeCode);
            if (indexTypeModel != null)
            {
                displayTimeFormat = indexTypeModel.displayTimeFormat;
                timeFormat = indexTypeModel.typeTimeFormat;
                precision = indexTypeModel.precisionField;

                // Check exist index
                param.Add("indexCode", index.indexCode);
                param.Add("term", index.term);
                param.Add("indexTypeCode", index.indexTypeCode);
                param.Add("seqNo", index.seqNo);
                param.Add("indexTime", index.indexTime);
                param.Add("displayTimeFormat", Int32.Parse(displayTimeFormat));

                Hashtable obj = (Hashtable)mapper.QueryForObject("Idx.selectIndex", param);
                index.updatedBy = userSession.userCode;
                index.createdBy = userSession.userCode;
                index.indexStatus = Constants.Status.Active;
                // If not exist -> Insert
                if (obj == null)
                {
                    mapper.Insert("Idx.insertIndex", index);
                }
                else // If exist -> Update
                {
                    param.Add("indexMoney", index.indexMoney);
                    param.Add("updatedBy", index.updatedBy);
                    mapper.Update("Idx.updateIndex", param);
                }
            }
            else
            {
                mapper.Insert("Idx.insertIndex", index);
            }
        }
Exemplo n.º 7
0
        public void ReadMoneyFile(MoneyFileUploadModels moneyFileUpload, SysUserModels userSession, string uploadFolder)
        {
            try
            {
                if (moneyFileUpload.moneyFile != null)
                {
                    //...
                    IExcelDataReader excelReader = null;

                    if (moneyFileUpload.moneyFile.ContentType.Contains("ms-excel"))
                    {
                        //1. Reading from a binary Excel file ('97-2003 format; *.xls)
                        excelReader = ExcelReaderFactory.CreateBinaryReader(moneyFileUpload.moneyFile.InputStream);
                    }
                    else
                    {
                        //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
                        excelReader = ExcelReaderFactory.CreateOpenXmlReader(moneyFileUpload.moneyFile.InputStream);
                    }
                    //...
                    //4. DataSet - Create column names from first row
                    excelReader.IsFirstRowAsColumnNames = true;
                    DataSet result = excelReader.AsDataSet();

                    DataTable dtData = result.Tables[0];

                    // Old
                    ExcelIndexReaderUtils excelUtils = new ExcelIndexReaderUtils();

                    if (StringUtils.IsEmpty(moneyFileUpload.moneyFile.FileName))
                    {
                        moneyFileUpload.errorMessage = Resource.MsgErrEmptyFile;
                        return;
                    }

                    string errorMsg = string.Empty;
                    IList<IdxIndexModels> indexList = excelUtils.GetMoneyFromExcel(dtData, this.mapper, out errorMsg);
                    if (!StringUtils.IsEmpty(errorMsg))
                    {
                        moneyFileUpload.errorMessage = errorMsg;
                    }

                    if (indexList != null)
                    {
                        // Save to db
                        for (int i = 0; i < indexList.Count; i++)
                        {
                            IdxIndexModels index = indexList[i];
                            try
                            {
                                this.SaveMoney(index, userSession);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.StackTrace);
                                moneyFileUpload.errorMessage = e.Message;
                                break;
                            }
                        }
                    }

                    //6. Free resources (IExcelDataReader is IDisposable)
                    excelReader.Close();
                }
                if (StringUtils.IsEmpty(moneyFileUpload.errorMessage))
                {
                    moneyFileUpload.infoMessage = Resource.MsgSuccess;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                //indexFileUpload.errorMessage = Resource.MsgErrUploadExcelFile;
                moneyFileUpload.errorMessage = ex.StackTrace;
            }
        }
Exemplo n.º 8
0
        private void persistUser(SysUserModels user, bool rememberMe)
        {
            // Create ticket
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,
                "user",
                DateTime.Now,
                DateTime.Now.AddMinutes(3),
                rememberMe,
                user.userCode,
                FormsAuthentication.FormsCookiePath);

            // Create encrypted cookie
            string hash = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
            if (ticket.IsPersistent)
            {
                cookie.Expires = ticket.Expiration;
            }

            // Set and done
            Response.Cookies.Add(cookie); //Necessary, otherwise UserData property gets lost
        }