/// <summary> /// File constructor /// </summary> /// <param name="str">GUID string</param> public File(string str) { Guid guid; if (!Guid.TryParse(str, out guid)) throw new ArgumentException(); _guid = str.ToUpper(); var si = new SqlIntegrate(Utility.ConnStr); si.AddParameter("@GUID", SqlIntegrate.DataType.VarChar, str.ToUpper()); var fileInfo = si.Reader("SELECT * FROM [File] WHERE [GUID] = @GUID"); _name = fileInfo["name"].ToString(); _info = fileInfo["info"].ToString(); _extension = fileInfo["extension"].ToString(); _size = Convert.ToInt32(fileInfo["size"]); _uploader = new User(Guid.Parse(fileInfo["uploader"].ToString())); _downloadCount = Convert.ToInt32(fileInfo["downloadCount"]); _uploadTime = Convert.ToDateTime(fileInfo["uploadTime"]); _savePath = StoragePath + str.ToUpper(); _permission = (PermissionLevel)Convert.ToInt32(fileInfo["permission"]); _mediaId = fileInfo["media_id"].ToString(); Tag = new List<string>(); si.ResetParameter(); si.AddParameter("@FUID", SqlIntegrate.DataType.VarChar, str.ToUpper()); var tagList = si.Adapter("SELECT [name] FROM [Filetag] WHERE FUID = @FUID"); for (var i = 0; i < tagList.Rows.Count; i++) Tag.Add(tagList.Rows[i]["name"].ToString()); }
/// <summary> /// Notification constructor (obtain a current one) /// </summary> /// <param name="id">Notification ID in database</param> public Notification(int id) { var si = new SqlIntegrate(Utility.ConnStr); si.AddParameter("@ID", SqlIntegrate.DataType.Int, id); var dr = si.Reader("SELECT * FROM Notification WHERE ID = @ID"); Content = dr["content"].ToString(); Title = dr["title"].ToString(); Id = id; Type = (PermissionType)int.Parse(dr["type"].ToString()); _group = -1; if (Type == PermissionType.SelfGroupOnly) _group = new User(Guid.Parse(dr["UUID"].ToString())).Group; NotifyTime = Convert.ToDateTime(dr["notifyTime"].ToString()); }
/// <summary> /// Mail constructor /// </summary> /// <param name="mailId">Mail ID in database</param> public Mail(int mailId) { _mailId = mailId; var si = new SqlIntegrate(ConnStr); si.AddParameter("@messageid", SqlIntegrate.DataType.Int, mailId); var mailInfo = si.Reader("SELECT * FROM hm_messages WHERE messageid = @messageid"); si.ResetParameter(); si.AddParameter("@messageid", SqlIntegrate.DataType.Int, mailId); Username = si.Query("DECLARE @uid int; SELECT @uid = messageaccountid FROM hm_messages WHERE messageid = @messageid; SELECT accountaddress FROM hm_accounts WHERE accountid = @uid;").ToString().Split('@')[0]; /* The eml file is storage in this way: * * When hmailserver receives an email, it writes information in database and stores the eml file. * * [A] = Hmailserver data path (need to set mailStoragePath in Web.config) * * [B] = Domain name (SAAO.Mail.mailDomain, need to set mailDomainName in Web.config) * * [C] = Username (without domain name, "szhang140" for example) * * [D] = Initial two characters (contain no open brace '{') of eml file name (store in [messagefilename] in database) * * [E] = Eml file name * * [F] = [A] \ [B] \ [C] \ [D] \ [E] ("D:\Mail_Data\xuehuo.org\szhang140\1B\{1B961C98-4FC8-40E3-BC8E-FA5A1D374381}.eml" for example) * * [F] is the absolute path to eml file. */ _emlPath = _mailPath + Username + @"\" + mailInfo["messagefilename"].ToString().Substring(1, 2) + @"\" + mailInfo["messagefilename"]; _message = ReadEml(_emlPath); Flag = (MailFlag)Convert.ToInt32(mailInfo["messageflags"]); Subject = _message.Subject; // Remove '<' and '>' From = new MailAddress( name: _message.From.Split('<')[0].Trim(), mail: _message.From.Split('<')[1].Replace(">", "").Trim() ); var toCount = _message.To.Trim().Split(',').Length; To = new List<MailAddress>(); for (var i = 0; i < toCount; i++) To.Add(new MailAddress( name: _message.To.Split(',')[i].Split('<')[0].Trim(), mail: _message.To.Split(',')[i].Split('<')[1].Replace(">","").Trim() )); SentOn = _message.SentOn; AttachmentCount = _message.Attachments.Count; }
/// <summary> /// User constructor /// </summary> /// <param name="uuid">User UUID</param> public User(Guid uuid) { UUID = uuid.ToString().ToUpper(); var si = new SqlIntegrate(Utility.ConnStr); si.AddParameter("@UUID", SqlIntegrate.DataType.VarChar, UUID); var dr = si.Reader("SELECT * FROM [User] WHERE [UUID] = @UUID"); _id = Convert.ToInt32(dr["ID"]); _password = dr["password"].ToString(); Realname = dr["realname"].ToString(); _sn = dr["SN"].ToString(); _class = Convert.ToInt32(dr["class"]); _mail = dr["mail"].ToString(); _phone = dr["phone"].ToString(); _wechat = dr["wechat"].ToString(); Initial = dr["username"].ToString()[dr["realname"].ToString().Length - 1] - 'a' + 1; Group = Convert.ToInt32(dr["group"].ToString()); Job = Convert.ToInt32(dr["job"].ToString()); GroupName = Organization.Current.GetGroupName(Group); JobName = Organization.Current.GetJobName(Job); if (_sn.Substring(0, 4) == Organization.Current.State.SeniorOne) Senior = 1; else if (_sn.Substring(0, 4) == Organization.Current.State.SeniorTwo) Senior = 2; }