Example #1
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;
        }
Example #2
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;
 }
Example #3
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");
 }
Example #4
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");
 }
Example #5
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");
 }
Example #6
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");
 }
Example #7
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");
 }
Example #8
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);
 }
Example #9
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);
 }
Example #10
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)");
 }
Example #11
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)");
 }
Example #12
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)");
 }