void identity_Leave(object sender, EventArgs e) { string errMsg = null; bool pass = TmoShare.isIdCardNo(identity.Text, out errMsg); if (!pass) { DXMessageBox.ShowWarning("输入的身份证号码不正确!\r\n原因:" + errMsg); identity.Focus(); return; } birthday.DateTime = Convert.ToDateTime(errMsg); }
void familymem1_Leave(object sender, EventArgs e) { string family1 = familymem1.Text.Trim(); if (!string.IsNullOrEmpty(family1)) { string errMsg = null; bool pass = TmoShare.isIdCardNo(family1, out errMsg); if (!pass) { DXMessageBox.ShowWarning("输入的身份证号码不正确!\r\n原因:" + errMsg); familymem1.Focus(); } } }
/// <summary> /// 定时更新年龄信息 /// </summary> /// <param name="state"></param> private void CalAge(object state) { if (DateTime.Now.TimeOfDay.TotalMinutes < 30) //12点到12点半之间更新 { int timestmp = ConfigHelper.GetConfigInt("AgeUpTime", 0, true); DateTime lasTime = DateTimeHelper.StampToTime(timestmp); if (DateTime.Today != lasTime.Date) { var dtUser = Tmo_FakeEntityManager.Instance.GetData("tmo_userinfo", new[] { "user_id", "birthday" }); if (TmoShare.DataTableIsNotEmpty(dtUser)) { List <string> sqlList = new List <string>(); foreach (DataRow row in dtUser.Rows) { string userid = row.GetDataRowStringValue("user_id"); DateTime birthTime = row.GetDataRowDateTimeValue("birthday"); if (birthTime == DateTime.MinValue || birthTime == DateTime.MaxValue) { string birthStr; if (TmoShare.isIdCardNo(userid, out birthStr)) { birthTime = Convert.ToDateTime(birthStr); } else { continue; } } int age = TmoShare.CalAge(birthTime); sqlList.Add(string.Format("update tmo_userinfo set age='{0}' where user_id='{1}'", age, userid)); } int count = MySQLHelper.ExecuteSqlList(sqlList); if (count > 0) { ConfigHelper.UpdateConfig("AgeUpTime", DateTimeHelper.TimeToStamp(DateTime.Now).ToString(), true); } } } } ((ManualResetEvent)((object[])state)[0]).Set(); }
public bool AddMonitorData(DataTable submitTable) { try { if (TmoShare.DataTableIsNotEmpty(submitTable)) { List <string> sqlList = new List <string>(); DataTable dtstruct = MemoryCacheHelper.GetCacheItem <DataTable>("ts_tmo_monitor", () => MySQLHelper.QueryTableStruct("tmo_monitor").Tables[0], DateTime.Now.AddHours(24)); DataTable dtstruct1 = MemoryCacheHelper.GetCacheItem <DataTable>("ts_tmo_monitor_received", () => MySQLHelper.QueryTableStruct("tmo_monitor_received").Tables[0], DateTime.Now.AddHours(24)); DataTable dtdic = MemoryCacheHelper.GetCacheItem <DataTable>("tmo_dicmonitor", () => MySQLHelper.QueryTable("select * from tmo_dicmonitor where is_del=0"), DateTime.Now.AddHours(12)); foreach (DataRow dr in submitTable.Rows) { int mt_code = TmoDataComm.GetMtCode(dr["mt_name"].ToString()); if (mt_code == 0) { continue; } if (dr["mt_value"] == null) { continue; //跳过空值 } string mt_valuetype = "mt_valuetext"; DataRow[] drsdic = dtdic.Select("mt_code=" + mt_code); if (drsdic.Length > 0) { switch (drsdic[0]["mt_valuetype"].ToString()) { case "0": mt_valuetype = "mt_valueint"; break; case "1": mt_valuetype = "mt_valuefloat"; break; case "2": default: mt_valuetype = "mt_valuetext"; break; } } if (mt_valuetype != "mt_valuetext" && string.IsNullOrWhiteSpace(dr["mt_value"].ToString())) { continue; //跳过无效值 } string user_id = dr["user_id"].ToString(); string errmsg; bool isUserId = TmoShare.isIdCardNo(user_id, out errmsg); if (!isUserId) { //查找设备绑定关系 object tmp_userid = MySQLHelper.QuerySingle( $"select a.dev_userid from tmo_monitor_devicebind a left join tmo_userinfo b on a.dev_userid=b.user_id where b.is_del!=1 and a.dev_sn='{user_id}'"); if (tmp_userid != null) { user_id = tmp_userid.ToString(); //找到绑定关系 isUserId = true; } } Dictionary <string, string> colVals = new Dictionary <string, string>(); colVals.Add("mt_code", mt_code.ToString()); colVals.Add("user_id", user_id); DateTime mt_time = dr.GetDataRowDateTimeValue("mt_time"); int mt_timestamp = dr.GetDataRowIntValue("mt_timestamp"); if (mt_timestamp == -1 || mt_timestamp == -2) //错误timestamp { if (mt_time == DateTime.MinValue || mt_time == DateTime.MaxValue || mt_time > DateTime.Now) //无效值 { mt_time = DateTime.Now; } mt_timestamp = DateTimeHelper.TimeToStamp(mt_time); } else { mt_time = DateTimeHelper.StampToTime(mt_timestamp); if (mt_time == DateTime.MinValue || mt_time == DateTime.MaxValue || mt_time > DateTime.Now) //无效值 { mt_time = DateTime.Now; } mt_timestamp = DateTimeHelper.TimeToStamp(mt_time); } dr["mt_time"] = mt_time; colVals.Add("mt_timestamp", mt_timestamp.ToString()); int sameType = 0; //相同类型 DataTable saveTableStruct = null; if (isUserId) { saveTableStruct = dtstruct; if (MySQLHelper.Exists("tmo_monitor", colVals)) { sameType = 1; //有相同时间数据 } colVals.Add(mt_valuetype, dr["mt_value"].ToString()); if (MySQLHelper.Exists("tmo_monitor", colVals)) { continue; //判断是否存在相同值 } } else { saveTableStruct = dtstruct1; sameType = 2; //存储到临时接收表 colVals.Add(mt_valuetype, dr["mt_value"].ToString()); if (MySQLHelper.Exists("tmo_monitor_received", colVals)) { continue; //判断是否存在相同值 } colVals.Add("remark", dr.GetDataRowStringValue("dev_type")); } foreach (DataColumn dc in submitTable.Columns) { string colname = dc.ColumnName; if (!saveTableStruct.Columns.Contains(colname)) { continue; //非monitor表中字段跳过 } if (colVals.ContainsKey(colname)) { continue; //已添加字段跳过 } colVals.Add(colname, dr[dc].ToString()); } if (sameType == 0) //插入 { StringBuilder sbsql = new StringBuilder("insert into tmo_monitor("); StringBuilder sbsqlval = new StringBuilder(" values("); foreach (var item in colVals) { sbsql.Append(item.Key + ","); sbsqlval.AppendFormat("{0},", item.Value == String.Empty ? "null" : $"'{item.Value}'"); } sbsql.Append("input_time)"); sbsqlval.Append("SYSDATE())"); sqlList.Add(sbsql.ToString() + sbsqlval.ToString()); } else if (sameType == 1) //修改 { StringBuilder sbsql = new StringBuilder("update tmo_monitor set "); sbsql.AppendFormat(" {0}='{1}' ", mt_valuetype, colVals[mt_valuetype]); sbsql.AppendFormat(", {0}='{1}' ", "mt_isnormal", colVals["mt_isnormal"]); sbsql.AppendFormat(", {0}={1} ", "input_time", "SYSDATE()"); sbsql.AppendFormat("where {0}='{1}' and {2}='{3}' and {4}='{5}'", "mt_code", colVals["mt_code"], "user_id", colVals["user_id"], "mt_timestamp", colVals["mt_timestamp"]); sqlList.Add(sbsql.ToString()); } else if (sameType == 2) //存储到临时接收表 { StringBuilder sbsql = new StringBuilder("insert into tmo_monitor_received("); StringBuilder sbsqlval = new StringBuilder(" values("); foreach (var item in colVals) { sbsql.Append(item.Key + ","); sbsqlval.AppendFormat("'{0}',", item.Value); } sbsql.Append("input_time)"); sbsqlval.Append("SYSDATE())"); sqlList.Add(sbsql.ToString() + sbsqlval.ToString()); } } int count = MySQLHelper.ExecuteSqlTran(sqlList); return(count >= 0); } else { return(true); } } catch (Exception ex) { LogHelper.Log.Error("添加监测数据失败", ex); return(false); } }