using Dapper; using dccdc.Models; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace dccdc.DAL { public class InfectionCheckDal { public int checkToday(string user_id) { string SQL = string.Format("select count(*) from dccdc.dbo.infection_check where user_id={0} and check_date=CONVERT(varchar(10),GETDATE(),120)", user_id); using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int i = conn.ExecuteScalar(SQL); return i; } catch (Exception ex) { return 0; } } } public object SaveData(InfectionCheckModel model) { string sql = @"Insert Into infection_check(user_id,state,check_date,create_time) Values (@user_id,@state,@check_date,@create_time)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int result = conn.Execute(sql, model); if (result > 0) return new { State = 1, Message = "签到成功!" }; else return new { State = 0, Message = "签到失败!" }; } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } public List GetAllDataList(string user_id) { string sql = "select isnull(c.state,0) as state,DATEPART(dd,d.date) as check_date from dccdc.dbo.infection_check c right join dccdc.dbo.infection_date d on c.check_date=d.date and c.user_id=" + user_id+" where d.year=DATENAME(YYYY,GETDATE()) and d.month=DATENAME(MM,GETDATE())"; //log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("sql====================" + sql); try { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql).ToList(); } } catch (Exception ex) { //log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("message====================" + ex.Message); return new List(); } } public int getCheckSum(string user_id) { string SQL = string.Format("select count(*) from dccdc.dbo.infection_check where user_id={0} and check_state=0 ", user_id); using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int i = conn.ExecuteScalar(SQL); return i; } catch (Exception ex) { return 0; } } } public bool updateCheckState(string user_id,int days) { string sql = @"update infection_check set check_state = 1 where id in (select TOP(@days) id from infection_check where user_id = @user_id And check_state = 0 order by create_time)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int result = conn.Execute(sql, new { @user_id = user_id, @days = days }); if (result > 0) return true; else return false; } catch (Exception ex) { return false; } } } public bool updateTodayCheckState(string user_id) { string sql = @"update infection_check set check_state = 1 where user_id = @user_id And check_state = 0 and check_date=CONVERT(varchar(10),GETDATE(),120)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int result = conn.Execute(sql, new { @user_id = user_id}); if (result > 0) return true; else return false; } catch (Exception ex) { return false; } } } } }