public void Task_Date_Not_Overlap() { DatetimeUtil datetime = new DatetimeUtil(); bool result = datetime.IsOverlapped("20200101", "20200115", "20200302", "20200401"); Assert.False(result); }
/// <summary> /// 上传外部单位附件 /// </summary> /// <param name="para"></param> /// <param name="trans"></param> /// <param name="objectID"></param> /// <param name="content"></param> /// <returns></returns> public string UploadAttachFileToResource(SessionPara para, SQLTransaction trans, string objectID, string content) { string retStr = ""; if (!string.IsNullOrEmpty(objectID) && !string.IsNullOrEmpty(content)) { StringBuilder sb = new StringBuilder(); var fileDataList = JsonConvert.DeserializeObject <List <FileInformation> >(content); foreach (var file in fileDataList) { var newObj = ObjectFactoryUtility.CreateInstance(para, trans, "TESTATTACH"); newObj.SetObjectDBValue("ENAME", file.FileName); newObj.SetObjectDBValue("PATH", file.Path); newObj.SetObjectDBValue("MASTERID", objectID); newObj.SetObjectDBValue("UPLOADUSER", para.UserID); newObj.SetObjectDBValue("UPLOADTIME", DatetimeUtil.GetInternalTicksByDateTime(DateTime.Now)); newObj.SetObjectDBValue("FILEINFO", JsonConvert.SerializeObject(new List <FileInformation>() { file })); newObj.SaveObject(para, trans); sb.Append(";" + newObj.ObjectID); } if (sb.Length > 0) { retStr = sb.ToString().Substring(1); } } return(retStr); }
public void Task_Date_Overlap() { DatetimeUtil datetime = new DatetimeUtil(); bool result = datetime.IsOverlapped("20200101", "20200130", "20200110", "20200401"); Assert.True(result); }
private void DoAddMember(string Pid, string Name, string Photo, string Sex, string Birthday, string Relation) { User _user = new User() { Pid = long.Parse(Pid), Name = Name, Birthday = DatetimeUtil.GetUnixTimeStamp(Birthday), Sex = Sex, Photourl = Photo, Relation = Relation }; UserRequest _userRequest = new UserRequest(); ServerResponse _serverResponse = _userRequest.AddMember(_user, false, string.Empty); Response.Write(JsonUtil.SerializeObject(_serverResponse)); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { if ("POST" == Request.HttpMethod) { //提交数据 string _name = Request["name"]; string _phoneNum = Request["phoneNum"]; string _sex = Request["sex"]; string _birthday = Request["birthday"]; string _userId = Request["userId"]; Family.Entity.User _user = new Family.Entity.User() { Name = _name, PhoneNum = _phoneNum, Sex = _sex, Birthday = DatetimeUtil.GetUnixTimeStamp(_birthday), UserId = _userId }; RegisterUser(_user); } }
public IActionResult Index(DateTime?Date, int?DateTimeOffset) { var rqf = Request.HttpContext.Features.Get <IRequestCultureFeature>(); var currentCulture = rqf.RequestCulture.Culture; //Birim Fiyat TL'dir var amount = 500; var dollar = _currencyService.Currencies.First(x => x.CurrencyCode == "Amerikan Doları").ForexSelling; var euro = _currencyService.Currencies.First(x => x.CurrencyCode == "Euro").ForexSelling; if (currentCulture.Name.StartsWith("en")) { ViewBag.Currency = (amount / dollar).ToString("c", new CultureInfo("en-US")); } else if (currentCulture.Name.StartsWith("fr")) { ViewBag.Currency = (amount / euro).ToString("c", new CultureInfo("fr-FR")); } else if (currentCulture.Name.StartsWith("tr")) { ViewBag.Currency = amount.ToString("c", new CultureInfo("tr-TR")); } if (Date.HasValue && DateTimeOffset.HasValue) { ViewBag.UTCDate = DatetimeUtil.FromUTCData(Date.Value, DateTimeOffset.Value); } ViewBag.Date = DateTime.Now; ViewBag.ControllerMessage = _localizer["ControllerTest"]; ViewData["genders"] = new SelectList(MUsefulMethods.EnumHelpers.ToKeyValuePair <Gender>(), "Key", "Value"); return(View(new ProductViewModel())); }
public Task <Response> GetHsitory(string[] itemids, string history, string time_from = null, string time_till = null) { long start_time; long end_time; if (string.IsNullOrEmpty(time_from) || string.IsNullOrEmpty(time_till)) { var now = DateTime.Now; end_time = DatetimeUtil.TimeToUnix(now); start_time = DatetimeUtil.TimeToUnix(now.AddHours(-1)); } else { start_time = DatetimeUtil.TimeToUnix(Convert.ToDateTime(time_from)); end_time = DatetimeUtil.TimeToUnix(Convert.ToDateTime(time_till)); } var zabbix = _provider.ZabbixLogin(); var result = zabbix.GetResponseObjectAsync("history.get", new { history, itemids, output = "extend", sortfield = "clock", sortorder = "ASC", time_from = start_time, time_till = end_time }); result.Wait(); _provider.ZabbixLogout(zabbix); return(result); }
public TimelineResponse(Timeline t) { id = t.id; content = t.content; pictures = t.pictures; location = t.location; createTime = DatetimeUtil.ConvertToTimestamp(t.createTime); try { DataContext mContext = new DataContext(); var userInfo = mContext.user.Where(p => p.id == t.userId).FirstOrDefault(); if (userInfo != null) { userName = userInfo.name; portrait = userInfo.portrait; } else { throw new ArgumentNullException(); } var lessonInfo = mContext.lesson.Where(p => p.id == t.lessonId).Select(p => p.name).FirstOrDefault(); if (lessonInfo != null) { lessonName = lessonInfo; } else { throw new ArgumentNullException(); } } catch (Exception e) { throw e; } }
private void UploadFile(HttpContext context) { string s_rpath = FileHelper.GetUploadPath(); string Datedir = DateTime.Now.ToString("yy-MM-dd"); string updir = s_rpath + "\\TransmitFile\\" + Datedir; string extname = string.Empty; string fullname = string.Empty; string filename = string.Empty; if (context.Request.Files.Count > 0) { try { for (int j = 0; j < context.Request.Files.Count; j++) { HttpPostedFile uploadFile = context.Request.Files[j]; int offset = Convert.ToInt32(context.Request["chunk"]); int total = Convert.ToInt32(context.Request["chunks"]); string name = context.Request["name"]; //文件没有分块 if (total == 1 || total == 0) { if (uploadFile.ContentLength > 0) { if (!System.IO.Directory.Exists(updir)) { System.IO.Directory.CreateDirectory(updir); } extname = System.IO.Path.GetExtension(uploadFile.FileName); filename = System.IO.Path.GetFileName(uploadFile.FileName); string filePath = string.Format("{0}\\{1}", updir, filename); uploadFile.SaveAs(filePath); ProcessFile(filePath, uploadFile.FileName); } } else { //文件 分成多块上传 fullname = WriteTempFile(uploadFile, offset); if (total - offset == 1) { //如果是最后一个分块文件 ,则把文件从临时文件夹中移到上传文件 夹中 System.IO.FileInfo fi = new System.IO.FileInfo(fullname); string oldFullName = string.Format("{0}\\{1}", updir, UploadFileName ?? uploadFile.FileName); System.IO.FileInfo oldFi = new System.IO.FileInfo(oldFullName); if (oldFi.Exists) { //文件名存在则删除旧文件 oldFi.Delete(); } if (!Directory.Exists(updir)) { Directory.CreateDirectory(updir); } fi.MoveTo(oldFullName); ProcessFile(oldFullName, uploadFile.FileName); } } } } catch (Exception ex) { JObject JResult = new JObject(); JResult.Add("State", "F"); JResult.Add("Msg", ex.Message); JResult.Add("Stack", ex.StackTrace); JResult.Add("TimeSpan", DatetimeUtil.GetInternalTicksByDateTime(DateTime.Now)); string json = JsonConvert.SerializeObject(JResult, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii }); HttpCookie hc = new HttpCookie("TFHResult", json); hc.Expires = DateTime.Now.AddMinutes(10); context.Response.AppendCookie(hc); File.AppendAllText("c:\\inforcenterdata\\TransmitFileHandler.log", Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine + ex.Message + ex.StackTrace); context.Response.StatusCode = 500; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(json); } } }