无法将类型为“ System.TimeSpan”的对象转换为类型为“ System.IConvertible”的对象。错误

时间:2019-08-30 06:08:55

标签: c#-4.0 asp.net-4.0 timespan

我有一个Web应用程序,该Web应用程序根据配置提供的最大中继数发送邮件。我只是分享一些代码,我将如何从两个日期开始评估这段时间。

DateTime? LastSentEmailDate = db.FromUsers.Where(f => f.EmailAddress.Equals(txt_ComName2.Text.Trim()) && f.user_id.Equals(int.Parse(CommonLogic.GetSessionValue("user_id").ToString()))).Select(f => f.SentDateTime).FirstOrDefault();
            if (LastSentEmailDate != null)
            {
                DateTime CurrentDate = DateTime.Now;
                var diffTimes = Convert.ToInt32((TimeSpan)(CurrentDate - LastSentEmailDate)); //difference as time you can use as miliseconds interval.TotalMilliSeconds              ---Error Occurs here
                int diffSentCount = 0;
                int? diffMaxCount = 0;
                diffSentCount = db.FromUsers.Where(f => f.EmailAddress.Equals(txt_ComName2.Text.Trim()) && f.user_id.Equals(int.Parse(CommonLogic.GetSessionValue("user_id").ToString()))).Select(f => f.Count).FirstOrDefault();
                diffMaxCount = db.FromUsers.Where(f => f.EmailAddress.Equals(txt_ComName2.Text.Trim()) && f.user_id.Equals(int.Parse(CommonLogic.GetSessionValue("user_id").ToString()))).Select(f => f.MaxCount).FirstOrDefault();
                int? difftotalcount = diffMaxCount - diffSentCount;
                if (diffTimes <= 3600000 && difftotalcount > 0)
                {
                    //Just sends mails 
                }
             else
            {
                ShowAlert("You Reach maximum limit of sending mail.please try after some time", this);
            }
        }
        else
        {
            db.ExecuteCommand(@"UPDATE [dbo].[tbl_From_master] SET [SentDateTime] = '" + DateTime.MinValue + "' WHERE [Id]='" + db.FromUsers.Where(f => f.EmailAddress.Equals(txt_ComName2.Text.Trim()) && f.user_id.Equals(int.Parse(CommonLogic.GetSessionValue("user_id").ToString()))).Select(f => f.Id).FirstOrDefault() + "'");
        }
    }
}

现在我已经知道如何实现此目标,请帮助我.....

0 个答案:

没有答案