/// <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> /// 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; }
///<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; }
/// <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; }
/// <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; }
/// <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); }
/// <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; }
/// <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"); }