public ResponseResult <string> PostBook([FromQuery] string token, string meetname, string room, string day, string hour, int status) { claim = (JwtClaim)_accessor.HttpContext.Items["user"]; try { //判断会议室是否停用 bool isstop = SystemService.IsStop(room, connstr); if (!isstop) { var h = hour.Split('至'); var start_hh = h[0].Split(':'); var start_hor = start_hh[0]; var start_min = start_hh.Count() <= 1?"00": start_hh[1]; var end_hh = h[1].Split(':'); var end_hor = end_hh[0]; var end_min = end_hh.Count() <= 1 ? "00" : end_hh[1]; var starttime = DateTime.Parse(day + " " + start_hor + ":" + start_min); var endtime = DateTime.Parse(day + " " + end_hor + ":" + end_min); if (starttime <= DateTime.Now) { return(ResponseResult <string> .Success("你是要穿越吗?", "你是要穿越吗?")); } //判断时段是否可用 bool enable = SystemService.AuthTime(room, starttime, endtime, connstr); if (enable) { //入库 SYS_BOOKINFO book = new SYS_BOOKINFO { MEETNAME = meetname, ROOMID = room, STARTTIME = starttime, ENDTIME = endtime, STATUS = status, UID = claim.uid }; var b = SystemService.BookRoom(book, connstr); if (b) { return(ResponseResult <string> .Success("操作成功", "操作成功")); } else { return(ResponseResult <string> .Success("操作失败", "操作失败")); } } else { return(ResponseResult <string> .Success("时间冲突", "时间冲突")); } } else { return(ResponseResult <string> .Success("会议室已停用", "会议室已停用")); } } catch (Exception ex) { return(ResponseResult <string> .Error("系统异常")); } }
public bool BookRoom(SYS_BOOKINFO book, string connectionString = null) { bool _user = false; string sql = $@"INSERT INTO `sys_bookinfo` ( `roomid`, `starttime`, `endtime`, `status`, `uid`, `meetname` ) VALUES ( '{book.ROOMID}', '{book.STARTTIME}', '{book.ENDTIME}', '{book.STATUS}', '{book.UID}', '{(book.MEETNAME)}' );" ; using (IDbConnection conn = DataBaseConfig.GetSqlConnection(DBType.mysql, connectionString)) { var obj = conn.Execute(sql); if (obj >= 1) { _user = true; } } return(_user); }
public bool UpdateBookInfo([FromBody] SYS_BOOKINFO value) { if (!ModelState.IsValid) { return(false); } if (string.IsNullOrEmpty(value.ID)) { return(false); } bool _result = false; DataTable dt = new DataTable("MyTable"); string sql = @" UPDATE `SYS_BOOKINFO` " + " SET `Name` = @Name, " + " `NickName` = @NickName, " + " `Email` = @Email, " + " `Phone` = @Phone, " + " `Sex` = @Sex, " + " `PlaceID` = @PlaceID, " + " `PeopleCount` = @PeopleCount, " + " `creator` = @Creator, " + " `creatorid` = @Creatorid, " + " `updatedate` = @Updatedate " + " WHERE `id` = @Id "; try { using (MySqlConnection conn = new MySqlConnection()) { conn.ConnectionString = DBCnstr; if (conn.State != ConnectionState.Open) { conn.Open(); } MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.Add(new MySqlParameter("@Id", value.ID)); cmd.Parameters.Add(new MySqlParameter("@Name", value.Name)); cmd.Parameters.Add(new MySqlParameter("@NickName", value.NickName)); cmd.Parameters.Add(new MySqlParameter("@Email", value.Email)); cmd.Parameters.Add(new MySqlParameter("@Phone", value.Phone)); cmd.Parameters.Add(new MySqlParameter("@Sex", value.Sex)); cmd.Parameters.Add(new MySqlParameter("@PlaceID", value.PlaceID)); cmd.Parameters.Add(new MySqlParameter("@PeopleCount", value.PeopleCount)); cmd.Parameters.Add(new MySqlParameter("@Creator", value.Creator)); cmd.Parameters.Add(new MySqlParameter("@Creatorid", value.CreatorID)); cmd.Parameters.Add(new MySqlParameter("@Updatedate", DateTime.Now)); int effectRow = cmd.ExecuteNonQuery(); cmd.Clone(); cmd.Dispose(); if (effectRow > 0) { _result = true; } } } catch (Exception ex) { //發信 myClass.myClass.SendMail("發生錯誤", "Exception:" + ex.Message, new List <string>()); } return(_result); }
public bool CreatBookInfo([FromBody] SYS_BOOKINFO value) { //驗證輸入結構是否符合 if (!ModelState.IsValid) { return(false); } bool _result = false; DataTable dt = new DataTable("MyTable"); string sql = " Insert Into `SYS_BOOKINFO` " + " (`ID`, " + " `Name` , " + " `NickName`, " + " `Email`, " + " `Phone`, " + " `Sex`, " + " `PlaceID`, " + " `PeopleCount`, " + " `Creator`, " + " `Creatorid`, " + " `Updatedate`) " + " Values (@ID, " + " @Name , " + " @NickName, " + " @Email, " + " @Phone, " + " @Sex, " + " @PlaceID, " + " @PeopleCount, " + " @Creator, " + " @Creatorid, " + " @Updatedate) "; try { using (MySqlConnection conn = new MySqlConnection()) { conn.ConnectionString = DBCnstr; if (conn.State != ConnectionState.Open) { conn.Open(); } MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.Add(new MySqlParameter("@Id", Guid.NewGuid().ToString())); cmd.Parameters.Add(new MySqlParameter("@Name", value.Name)); cmd.Parameters.Add(new MySqlParameter("@NickName", value.NickName)); cmd.Parameters.Add(new MySqlParameter("@Email", value.Email)); cmd.Parameters.Add(new MySqlParameter("@Phone", value.Phone)); cmd.Parameters.Add(new MySqlParameter("@Sex", value.Sex)); cmd.Parameters.Add(new MySqlParameter("@PlaceID", value.PlaceID)); cmd.Parameters.Add(new MySqlParameter("@PeopleCount", value.PeopleCount)); cmd.Parameters.Add(new MySqlParameter("@Creator", value.Creator)); cmd.Parameters.Add(new MySqlParameter("@Creatorid", value.CreatorID)); cmd.Parameters.Add(new MySqlParameter("@Updatedate", DateTime.Now)); int effectRow = cmd.ExecuteNonQuery(); cmd.Clone(); cmd.Dispose(); if (effectRow > 0) { _result = true; } } } catch (Exception ex) { //發信 myClass.myClass.SendMail("發生錯誤", "Exception:" + ex.Message, new List <string>()); } return(_result); }