Exemple #1
0
        protected override bool BeforeSubmitData(Dictionary <string, object> dicData)
        {
            if (dicData == null || dicData.Count < 1)
            {
                return(false);
            }

            try
            {
                if (DbOperaType == DBOperateType.Add)
                {
                    string identity  = dicData["identity"].ToString();
                    bool   existSame = Tmo_FakeEntityClient.Instance.ExistSameValue(TableName, "user_id", identity);
                    if (existSame)
                    {
                        DXMessageBox.ShowWarning2("已存在相同的用户!请检查信息是否正确");
                        return(false);
                    }
                    existSame = Tmo_FakeEntityClient.Instance.ExistSameValue(TableName, "user_id", identity, null, false);
                    if (existSame)
                    {   //之前建立过相关用户档案
                        DbOperaType     = DBOperateType.Update;
                        PrimaryKeyValue = identity;
                        dicData.Add("is_del", 0);
                    }
                    else
                    {
                        dicData.Add("user_id", dicData["identity"]);
                    }
                    if (!dicData.ContainsKey("user_pwd"))
                    {
                        dicData.Add("user_pwd", Convert.ToDateTime(dicData["birthday"].ToString()).ToString("yyyyMMdd"));
                    }
                    dicData.Add("doc_id", TmoComm.login_docInfo.doc_id);
                }
                dicData.Add("age", TmoShare.CalAge(Convert.ToDateTime(dicData["birthday"].ToString())));    //修改时更新年龄
                dicData[dpt_id.Name] = dpt_id.Tag;
                dicData.Add("retire", dpt_id.Text);

                userinfo = ModelConvertHelper <Userinfo> .ConvertToOneModel(dicData);

                return(true);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error("提交用户信息失败", ex);
                return(false);
            }
        }
        /// <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();
        }