/// <summary> /// 静态方法。转换为System.DateTime类型。 /// </summary> /// <param name="time">SYSTEMTIME类型的时间。</param> /// <returns></returns> public static DateTime ToDateTime(SYSTEMTIME time) { return(time.ToDateTime()); }
public static extern void GetLocalTime(ref SYSTEMTIME time);
public static extern void GetSystemTime(ref SYSTEMTIME time);
public static extern bool SetLocalTime(ref SYSTEMTIME time);
public static extern bool SetSystemTime(ref SYSTEMTIME time);
/// <summary> /// 通过配置文件设置机构信息 /// </summary> private static void SetBranchInfo() { // 获取机构ID,默认为1. string sid = ConfigurationManager.AppSettings.Get("BranchId"); if (!sid.IsNullOrEmpty() && sid.IsInt()) { EnvInfo.BranchId = int.Parse(sid); } else { EnvInfo.BranchId = 1; } string key = ConfigurationManager.AppSettings.Get("UserSerial").Reversal(); // 获取用户名称 string rets = ConfigurationManager.AppSettings.Get("UserName"); if (!string.IsNullOrEmpty(rets)) { rets = DataCryptoHelper.Decrypting(rets, "Wonder.His" + key); EnvInfo.UserName = rets; } else { throw new Exception("配置文件中用户名称有误!"); } //try //{ // 系统时间与数据库时间同步 DateTime d = DateTime.Now; //int timezone = int.Parse(DateTime.Now.ToString("%z").Substring(1)); CustomException ex = null; String systime = HttpDataHelper.GetStringWithInfo("BASE", "/sys/date", out ex); if (ex != null) { throw ex; } char[] spp = new char[] { '-', ':', ' ', '+' }; string[] tp = systime.Split(spp, StringSplitOptions.RemoveEmptyEntries); int[] itp = new int[7]; for (int i = 0; i < 7; i++) { itp[i] = int.Parse(tp[i]); } DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(itp[0], itp[1], itp[2], itp[3], itp[4], itp[5])); long delta = GetTimeStamp(startTime) - GetTimeStamp(d) - itp[6] * 36000; //时区处理 if (Math.Abs(delta) < 60000) { SYSTEMTIME st = new SYSTEMTIME(); st.FromDateTime(DateTime.Now.AddMilliseconds(delta)); bool syn = Win32API.SetLocalTime(ref st); if (!syn) { EnvInfo.ServerTimeDelta = delta; } } // 通过BranchId 查询 名称及代码 List <KeyValuePair <string, string> > parms = new List <KeyValuePair <string, string> >(); parms.Add(new KeyValuePair <string, string>("branchId", EnvInfo.BranchId.ToString())); CustomException ce = null; CDictBranch branch = HttpDataHelper.GetWithInfo <CDictBranch>("BASE", "/sys/branch", out ce, parms); EnvInfo.BranchCode = branch.Code; // "101"; EnvInfo.BranchName = branch.Name; // EnvInfo.UserName; #region MONGODB 测试 //ErrorLogInfo eli = new ErrorLogInfo(); //eli.BranchId = EnvInfo.BranchId; //eli.EmpId = EmpInfo.Id; //eli.ComputerIp = EnvInfo.ComputerIp; //eli.Info = "Try"; //eli.Message = "Demo message"; //String json = StringHelper.SerializeObject<ErrorLogInfo>(eli); //HttpDataHelper.HttpPostWithInfo"BASE", "/mongo/errorlog/save", json); #endregion //} //catch (Exception ex) //{ // MessageHelper.ShowError(ex.Message); //} }