Esempio n. 1
0
 /// <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());
 }
Esempio n. 2
0
        /// <summary>
        /// Create or update an event
        /// </summary>
        /// <returns>A new id of the event (GUID)</returns>
        public static JObject UpdateEvent(JObject event_obj)
        {
            var si = new SqlIntegrate(Utility.ConnStr);
            si.AddParameter("@event_text", SqlIntegrate.DataType.NVarChar, event_obj["event_text"]);
            si.AddParameter("@start_date", SqlIntegrate.DataType.VarChar, ChangeDateFormat(event_obj["start_date"].ToString()));
            si.AddParameter("@end_date", SqlIntegrate.DataType.VarChar, ChangeDateFormat(event_obj["end_date"].ToString()));

            var event_text = event_obj["event_text"].ToString();
            var group_tag = event_text.Length > 2 ? event_text.Substring(0, 2) : event_text;
            var group_index = -1;
            var group_color = UnknownGroupColor;
            if (group_tag == "全体")
            {
                group_index = -2; group_color = AllGroupColor;
            }
            else if(group_tag == "非技")
            {
                group_index = -3; group_color = FeijiColor;
            }
            else if(group_tag == "技术")
            {
                group_index = -4; group_color = JishuColor;
            }
            else
            {
                group_index = Organization.Current.GetGroupIndex(group_tag + "组");
                if (group_index == -1)
                    group_color = UnknownGroupColor;
                else
                    group_color = Organization.Current.GetGroupColor(group_index);
            }
            si.AddParameter("@group", SqlIntegrate.DataType.Int, group_index);
            si.AddParameter("@color", SqlIntegrate.DataType.VarChar, group_color);

            var back = new JObject { ["idORerr"] = "", ["color"] = group_color };

            Guid event_guid;
            if (Guid.TryParse(event_obj["event_id"].ToString(), out event_guid))
            {
                //update
                si.AddParameter("@event_id", SqlIntegrate.DataType.VarChar, event_guid.ToString().ToUpper());
                back["idORerr"] = si.Execute("UPDATE [Calendar] SET [text] = @event_text, [start_date] = @start_date, [end_date] = @end_date, [group] = @group, [color] = @color WHERE [id] = @event_id") == 0 ? "event-does-not-exist" : event_guid.ToString().ToUpper();
            }
            else
            {
                //create
                string new_guid = Guid.NewGuid().ToString().ToUpper();
                si.AddParameter("@event_id", SqlIntegrate.DataType.VarChar, new_guid);
                si.Execute("INSERT INTO [Calendar] ([id], [text], [start_date], [end_date], [group], [color]) VALUES (@event_id, @event_text, @start_date, @end_date, @group, @color)");
                back["idORerr"] = new_guid;
            }
            return back;
        }
Esempio n. 3
0
 /// <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());
 }
Esempio n. 4
0
 /// <summary>
 /// Notification constructor (create a new one)
 /// </summary>
 /// <param name="title">Notification title</param>
 /// <param name="content">Notification content</param>
 /// <param name="type">Notification type</param>
 public Notification(string title, string content, PermissionType type)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@title", SqlIntegrate.DataType.NVarChar, title, 50);
     si.AddParameter("@content", SqlIntegrate.DataType.Text, content);
     si.AddParameter("@type", SqlIntegrate.DataType.Int, (int)type);
     si.AddParameter("@UUID", SqlIntegrate.DataType.VarChar, User.Current.UUID);
     Id = Convert.ToInt32(si.Query("INSERT INTO Notification ([title], [content], [type], [UUID]) VALUES (@title, @content, @type, @UUID); SELECT @@IDENTITY"));
     Type = type;
     Title = title;
     Content = content;
     _group = -1;
     if (type == PermissionType.SelfGroupOnly)
         _group = User.Current.Group;
     NotifyTime = DateTime.Now;
 }
Esempio n. 5
0
 /// <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;
 }
Esempio n. 6
0
 /// <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;
 }
Esempio n. 7
0
 /// <summary>
 /// Delete an event
 /// </summary>
 public static void DeleteEvent(string event_id)
 {
     SqlIntegrate si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@event_id", SqlIntegrate.DataType.VarChar, event_id);
     si.Execute("DELETE FROM [Calendar] WHERE [id] = @event_id");
 }
Esempio n. 8
0
 public static void Upload(System.Web.HttpPostedFile file)
 {
     var guid = Guid.NewGuid().ToString().ToUpper();
     file.SaveAs(StoragePath + guid);
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@GUID", SqlIntegrate.DataType.VarChar, guid);
     si.AddParameter("@name", SqlIntegrate.DataType.VarChar,
         Path.GetFileNameWithoutExtension(file.FileName), 50);
     si.AddParameter("@extension", SqlIntegrate.DataType.VarChar,
         Path.GetExtension(file.FileName).TrimStart('.').ToLower(), 10);
     si.AddParameter("@size", SqlIntegrate.DataType.Int, file.ContentLength);
     si.AddParameter("@UUID", SqlIntegrate.DataType.VarChar, User.Current.UUID);
     si.Execute("INSERT INTO [File] ([GUID],[name],[extension],[size],[uploader]) VALUES (@GUID,@name,@extension,@size,@UUID)");
 }
Esempio n. 9
0
 ///<summary>
 ///List beginning/ongoing/ending missions in JArray
 ///</summary>
 ///<return>list of mission names corresponding to the type</return>
 private static JArray ListMissionNames(string type)
 {
     SqlIntegrate si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@group", SqlIntegrate.DataType.Int, User.Current.Group);
     si.AddParameter("@dept", SqlIntegrate.DataType.Int, Dept[User.Current.Group]);
     si.AddParameter("@sd", SqlIntegrate.DataType.DateTime, DateTime.Today);
     si.AddParameter("@ed", SqlIntegrate.DataType.DateTime, DateTime.Today.AddDays(1));
     DataTable dt;
     if (type == "begin")
         dt = si.Adapter("SELECT [text] FROM [Calendar] WHERE ([group]=@group OR [group]='-2' OR [group]=@dept) AND [start_date]>=@sd AND [start_date]<@ed");
     else if (type == "end")
         dt = si.Adapter("SELECT [text] FROM [Calendar] WHERE ([group]=@group OR [group]='-2' OR [group]=@dept) AND [end_date]>@sd AND [end_date]<=@ed");
     else
         dt = si.Adapter("SELECT [text] FROM [Calendar] WHERE ([group]=@group OR [group]='-2' OR [group]=@dept) AND [start_date]<@sd AND [end_date]>@ed");
     var array = new JArray();
     foreach (DataRow r in dt.Rows)
     {
         array.Add(r[0].ToString());
     }
     return array;
 }
Esempio n. 10
0
 /// <summary>
 /// Check whether the file has a tag
 /// </summary>
 /// <param name="str">Tag string</param>
 /// <returns>whether the file has this tag</returns>
 public bool HasTag(string str)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@name", SqlIntegrate.DataType.VarChar, str, 50);
     si.AddParameter("@FUID", SqlIntegrate.DataType.VarChar, _guid);
     var count = Convert.ToInt32(si.Query(
         "SELECT COUNT(*) FROM [Filetag] WHERE [name] = @name AND [FUID] = @FUID"));
     return count != 0;
 }
Esempio n. 11
0
 /// <summary>
 /// Set a new flag of the mail
 /// </summary>
 /// <param name="newflag">New flag</param>
 public void SetFlag(MailFlag newflag)
 {
     var si = new SqlIntegrate(ConnStr);
     si.AddParameter("@messageflags", SqlIntegrate.DataType.Int, (int)newflag);
     si.AddParameter("@messageid", SqlIntegrate.DataType.Int, _mailId);
     si.Execute("UPDATE hm_messages SET messageflags = @messageflags WHERE messageid = @messageid");
     Flag = newflag;
 }
Esempio n. 12
0
 /// <summary>
 /// Check whether the user of a username exists and is activated
 /// </summary>
 /// <param name="username"></param>
 /// <returns>Whether the user of a username exists and is activated</returns>
 public static bool Exist(string username)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@username", SqlIntegrate.DataType.VarChar, username, 50);
     var count = Convert.ToInt32(si.Query("SELECT COUNT(*) FROM [User] WHERE [username] = @username AND [activated] = 1"));
     return count == 1;
 }
Esempio n. 13
0
 /// <summary>
 /// Wechat Login
 /// </summary>
 /// <param name="wechatId">Wechat ID(username)</param>
 /// <returns>Whether the wechat ID has been bound</returns>
 public static bool WechatLogin(string wechatId)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@wechat", SqlIntegrate.DataType.VarChar, wechatId);
     var r = si.Query(
         "SELECT [username] FROM [User] WHERE [wechat] = @wechat");
     if (r == null) return false;
     Current = new User(r.ToString());
     // TODO: no raw password raw storage!
     return true;
 }
Esempio n. 14
0
 /// <summary>
 /// Add a tag to the file
 /// </summary>
 /// <param name="str">Tag string</param>
 public void AddTag(string str)
 {
     Tag.Add(str);
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@name", SqlIntegrate.DataType.NVarChar, str, 50);
     si.AddParameter("@FUID", SqlIntegrate.DataType.VarChar, _guid);
     si.Execute("INSERT INTO Filetag ([name], [FUID]) VALUES (@name, @FUID)");
 }
Esempio n. 15
0
 /// <summary>
 /// Organization structure constructor
 /// </summary>
 /// <param name="dt">Datetime (DateTime.Now most possibly)</param>
 public Organization(DateTime dt)
 {
     State = new State(dt);
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@year", SqlIntegrate.DataType.VarChar, State.StructureCurrent + (int)State.EventCurrent);
     Structure = si.Adapter("SELECT * FROM [Org] WHERE [year] = @year");
 }
Esempio n. 16
0
 /// <summary>
 /// Broadcast the notification by sending email
 /// </summary>
 public void Broadcast()
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     DataTable dt;
     if (_group == -1)
         dt = si.Adapter("SELECT [wechat] FROM [User] WHERE activated = 1 AND [wechat] != ''");
     else
     {
         si.AddParameter("@group", SqlIntegrate.DataType.Int, _group);
         dt = si.Adapter("SELECT [wechat] FROM [User] WHERE activated = 1 AND [group] = @group AND [wechat] != ''");
     }
     var toSend = "";
     for (var i = 0; i < dt.Rows.Count; i++)
     {
         if (toSend != "")
             toSend += "|";
         toSend += dt.Rows[i]["wechat"].ToString();
     }
     var o = new JObject
     {
         ["touser"] = toSend,
         ["msgtype"] = "news",
         ["agentid"] = 4,
         ["news"] = new JObject
         {
             ["articles"] = new JArray
             {
                 new JObject
                 {
                     ["title"] = Title,
                     ["description"] = Content
                 }
             }
         }
     };
     Utility.HttpRequest($"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={Utility.GetAccessToken()}", o);
 }
Esempio n. 17
0
 /// <summary>
 /// Set an important flag
 /// </summary>
 public void SetImportant()
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@ID", SqlIntegrate.DataType.Int, Id);
     si.Execute("UPDATE Notification SET important = ((SELECT MAX(important) FROM Notification) + 1) WHERE ID = @ID");
 }
Esempio n. 18
0
 /// <summary>
 /// Attach supervising report
 /// </summary>
 /// <param name="guid">Supervising report storage GUID</param>
 public void AttachReport(string guid)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@reportFile", SqlIntegrate.DataType.VarChar, guid);
     si.AddParameter("@ID", SqlIntegrate.DataType.Int, Id);
     si.Execute("UPDATE Notification SET reportFile = @reportFile WHERE ID = @ID");
 }
Esempio n. 19
0
 /// <summary>
 /// Delete the file
 /// </summary>
 public void Delete()
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@GUID", SqlIntegrate.DataType.VarChar, _guid);
     si.Execute("DELETE FROM [File] WHERE [GUID] = @GUID");
     si.ResetParameter();
     si.AddParameter("@FUID", SqlIntegrate.DataType.VarChar, _guid);
     si.Execute("DELETE FROM [Filetag] WHERE [FUID] = @FUID");
     System.IO.File.Delete(_savePath);
 }
Esempio n. 20
0
 /// <summary>
 /// Remove a tag of the file (if existed)
 /// </summary>
 /// <param name="str">Tag string</param>
 public void RemoveTag(string str)
 {
     if (!HasTag(str)) return;
     Tag.Remove(str);
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@name", SqlIntegrate.DataType.NVarChar, str, 50);
     si.AddParameter("@FUID", SqlIntegrate.DataType.VarChar, _guid);
     si.Execute("DELETE FROM [Filetag] WHERE [name] = @name AND [FUID] = @FUID");
 }
Esempio n. 21
0
 /// <summary>
 /// List current events in the database in JSON
 /// </summary>
 /// <returns>JSON of current events [{title,start,end,backgroundColor},...]</returns>
 public static JArray ListJson()
 {
     SqlIntegrate si = new SqlIntegrate(Utility.ConnStr);
     return si.AdapterJson("SELECT * FROM [Calendar]");
 }
Esempio n. 22
0
 /// <summary>
 /// List current notifications in the database in JSON
 /// </summary>
 /// <returns>JSON of current notifications [{ID,title,user,content,notifyTime,type,imprtant,(reportFile)},...]</returns>
 public static JArray ListJson()
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@start", SqlIntegrate.DataType.Date, Organization.Current.State.EventStart);
     si.AddParameter("@end", SqlIntegrate.DataType.Date, Organization.Current.State.EventEnd);
     var dt = si.Adapter("SELECT [Notification].[reportFile], [Notification].[ID], [Notification].[important], [Notification].[type], [Notification].[title], [Notification].[content], [Notification].[notifyTime], [User].[realname], [User].[group] FROM [Notification] INNER JOIN [User] ON [Notification].[UUID] = [User].[UUID] AND [Notification].[notifyTime] BETWEEN @start AND @end ORDER BY Notification.important DESC, ID DESC");
     var a = new JArray();
     for (var i = 0; i < dt.Rows.Count; i++)
     {
         if (!Visible(Convert.ToInt32(dt.Rows[i]["group"]), PermissionType.SelfGroupOnly)) continue;
         var o = new JObject
         {
             ["ID"] = dt.Rows[i]["ID"].ToString(),
             ["title"] = dt.Rows[i]["title"].ToString(),
             ["user"] = dt.Rows[i]["realname"].ToString(),
             ["content"] = dt.Rows[i]["content"].ToString(),
             ["notifyTime"] =
                 Convert.ToDateTime(dt.Rows[i]["notifyTime"]).ToString("yyyy-MM-dd HH:mm"),
             ["type"] = dt.Rows[i]["type"].ToString(),
             ["important"] = Convert.ToInt32(dt.Rows[i]["important"])
         };
         if (Convert.ToInt32(dt.Rows[i]["type"]) == (int)PermissionType.Supervise)
             o["reportFile"] = dt.Rows[i]["reportFile"].ToString();
         a.Add(o);
     }
     return a;
 }
Esempio n. 23
0
 /// <summary>
 /// List current files in the database in JSON
 /// </summary>
 /// <returns>JSON of current files [{guid,name,extension,uploaderName,datetime,info(bool)},...]</returns>
 public static JArray ListJson(DateTime start, DateTime end)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@start", SqlIntegrate.DataType.Date, start);
     si.AddParameter("@end", SqlIntegrate.DataType.Date, end);
     var dt = si.Adapter("SELECT [File].*, [User].[realname], [User].[group] FROM [File] INNER JOIN [User] ON [File].[uploader] = [User].[UUID] AND [File].[uploadTime] BETWEEN @start AND @end ORDER BY [File].[ID] DESC");
     var a = new JArray();
     for (var i = 0; i < dt.Rows.Count; i++)
     {
         if (
             !Visible((PermissionLevel) Convert.ToInt32(dt.Rows[i]["permission"].ToString()),
                 dt.Rows[i]["uploader"].ToString(), Convert.ToInt32(dt.Rows[i]["group"]),
                 User.Current)) continue;
         var o = new JObject
         {
             ["guid"] = dt.Rows[i]["GUID"].ToString(),
             ["name"] = dt.Rows[i]["name"].ToString(),
             ["extension"] = dt.Rows[i]["extension"].ToString(),
             ["downloadCount"] = int.Parse(dt.Rows[i]["downloadCount"].ToString()),
             ["uploaderName"] = dt.Rows[i]["realname"].ToString(),
             ["datetime"] = DateTime.Parse(dt.Rows[i]["uploadTime"].ToString()).ToString("yyyy-MM-dd HH:mm"),
             ["info"] = dt.Rows[i]["info"].ToString() != ""
         };
         a.Add(o);
     }
     return a;
 }
Esempio n. 24
0
 /// <summary>
 /// List mail(s) of a folder in the database in JSON
 /// </summary>
 /// <param name="folder">Folder name</param>
 /// <returns>JSON of mail(s) of the folder [{id,subject,from,thumb,flag,time,attachcount},...]</returns>
 public static JArray ListJson(string folder)
 {
     var si = new SqlIntegrate(ConnStr);
     si.AddParameter("@accountaddress", SqlIntegrate.DataType.VarChar, User.Current.Username + "@" + MailDomain);
     si.AddParameter("@foldername", SqlIntegrate.DataType.VarChar, folder);
     var list = si.Adapter(
         "DECLARE @uid int; SELECT @uid = accountid FROM hm_accounts WHERE accountaddress = @accountaddress;" +
         "SELECT messageid FROM hm_messages WHERE messagefolderid = (SELECT folderid FROM hm_imapfolders WHERE foldername = @foldername AND folderaccountid = @uid) AND messageaccountid = @uid ORDER BY messageid DESC");
     var a = new JArray();
     for (var i = 0; i < list.Rows.Count; i++)
     {
         var message = new Mail(Convert.ToInt32(list.Rows[i]["messageid"]));
         var o = new JObject
         {
             ["id"] = list.Rows[i]["messageid"].ToString(),
             ["subject"] = message.Subject,
             ["from"] = message.From.Name,
             ["thumb"] = message.Thumb(),
             ["flag"] = (int) message.Flag,
             ["time"] = message.SentOn.ToString("yyyy-MM-dd HH:mm"),
             ["attachcount"] = message.AttachmentCount
         };
         a.Add(o);
     }
     return a;
 }
Esempio n. 25
0
 /// <summary>
 /// List activated users in the database in JSON
 /// </summary>
 /// <returns>JSON of activated users. [{realname,senior,group,initial,jobName,groupName,phone,mail},...]</returns>
 public static JArray ListJson()
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     var dt = si.Adapter("SELECT * FROM [User] WHERE [activated] = 1");
     var a = new JArray();
     for (var i = 0; i < dt.Rows.Count; i++)
     {
         var o = new JObject
         {
             ["realname"] = dt.Rows[i]["realname"].ToString(),
             ["senior"] =
                 (dt.Rows[i]["SN"].ToString().Substring(0, 4) == Organization.Current.State.StructureCurrent)
                     ? 2
                     : 1,
             ["group"] = dt.Rows[i]["group"].ToString(),
             ["initial"] = dt.Rows[i]["username"].ToString()[dt.Rows[i]["realname"].ToString().Length - 1] - 'a' + 1,
             ["jobName"] = Organization.Current.GetJobName(Convert.ToInt32(dt.Rows[i]["job"].ToString())),
             ["groupName"] = Organization.Current.GetGroupName(Convert.ToInt32(dt.Rows[i]["group"].ToString())),
             ["phone"] = dt.Rows[i]["phone"].ToString(),
             ["mail"] = dt.Rows[i]["mail"].ToString(),
             ["class"] = int.Parse(dt.Rows[i]["class"].ToString())
         };
         a.Add(o);
     }
     return a;
 }
Esempio n. 26
0
 /// <summary>
 /// Move the mail to another folder
 /// </summary>
 /// <param name="folderName">Target folder name</param>
 public void MoveTo(string folderName)
 {
     var si = new SqlIntegrate(ConnStr);
     si.AddParameter("@accountaddress", SqlIntegrate.DataType.VarChar, User.Current.Username + "@" + MailDomain);
     si.AddParameter("@foldername", SqlIntegrate.DataType.VarChar, folderName);
     si.AddParameter("@messageid", SqlIntegrate.DataType.Int, _mailId);
     si.Execute("DECLARE @uid int; SELECT @uid = accountid FROM hm_accounts WHERE accountaddress = @accountaddress;" +
         "UPDATE hm_messages SET messagefolderid = (SELECT folderid FROM hm_imapfolders WHERE foldername = @foldername AND folderaccountid = @uid) WHERE messageid = @messageid");
 }
Esempio n. 27
0
 /// <summary>
 /// Write message (error one most possibly) to database
 /// </summary>
 /// <param name="message">Exception</param>
 public static void Log(Exception message)
 {
     var si = new SqlIntegrate(ConnStr);
     si.AddParameter("@context", SqlIntegrate.DataType.Text, message.Message + message.StackTrace);
     si.AddParameter("@url", SqlIntegrate.DataType.Text, HttpContext.Current.Request.Url.ToString());
     si.AddParameter("@IP", SqlIntegrate.DataType.Text, HttpContext.Current.Request.UserHostAddress);
     si.AddParameter("@browser", SqlIntegrate.DataType.Text, HttpContext.Current.Request.UserAgent);
     si.AddParameter("@OS", SqlIntegrate.DataType.Text, HttpContext.Current.Request.Browser.Platform);
     si.AddParameter("@session", SqlIntegrate.DataType.Text, User.IsLogin ? User.Current.Username : "******");
     si.Execute("INSERT INTO Log ([context], [url], [IP], [browser], [OS], [session]) VALUES (@context, @url, @IP, @browser, @OS, @session)");
 }
Esempio n. 28
0
 /// <summary>
 /// Download the file (Write stream to current http response)
 /// </summary>
 public void Download()
 {
     _downloadCount++;
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@GUID", SqlIntegrate.DataType.VarChar, _guid);
     si.Execute("UPDATE [File] SET [downloadCount] = [downloadCount] + 1 WHERE [GUID] = @GUID");
     Utility.Download(_savePath, _name + "." + _extension);
 }