예제 #1
0
        }                                               // 参照时间点

        /// <summary>
        /// 找到最近的参照时间点
        /// </summary>
        protected void GetReferenceTime()
        {
            // 找到参照时间点(在最小间隔外,推算时间点)
            DateTime time = BeginDate.CompareTo(DateTime.Now) > 0 ? BeginDate : DateTime.Now;

            referenceTime = time.AddSeconds(MinInterval);
        }
예제 #2
0
        /// <summary>
        /// 创建访客记录
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

        private string CreateVisitor(DataRow row)
        {
            try
            {
                #region 获取参数并简单校验
                string Mobile = string.Empty;
                if (row.Table.Columns.Contains("Mobile"))
                {
                    Mobile = row["Mobile"].ToString();
                }
                if (string.IsNullOrEmpty(Mobile))
                {
                    return(new WxResponse(0, "用户不存在", null).toJson());
                }
                if (Mobile.Length != 11)
                {
                    return(new WxResponse(0, "用户不存在", null).toJson());
                }
                if (!row.Table.Columns.Contains("UserID") || !int.TryParse(row["UserID"].ToString(), out int UserID))
                {
                    return(new WxResponse(0, "用户不存在", null).toJson());
                }
                string MemberName = string.Empty;
                if (row.Table.Columns.Contains("MemberName"))
                {
                    MemberName = row["MemberName"].ToString();
                }
                if (string.IsNullOrEmpty(MemberName))
                {
                    return(new WxResponse(0, "访客姓名不能为空", null).toJson());
                }
                string MemberMobile = string.Empty;
                if (row.Table.Columns.Contains("MemberMobile"))
                {
                    MemberMobile = row["MemberMobile"].ToString();
                }
                if (string.IsNullOrEmpty(MemberMobile))
                {
                    return(new WxResponse(0, "访客电话不能为空", null).toJson());
                }
                if (MemberMobile.Length != 11)
                {
                    return(new WxResponse(0, "访客电话不正确", null).toJson());
                }
                if (!row.Table.Columns.Contains("MemberType") || !int.TryParse(row["MemberType"].ToString(), out int MemberType))
                {
                    return(new WxResponse(0, "请选择访客类型", null).toJson());
                }
                if (MemberType != 0 && MemberType != 1 && MemberType != 2)
                {
                    return(new WxResponse(0, "访客类型不正确", null).toJson());
                }
                if (!row.Table.Columns.Contains("BeginDate") || !DateTime.TryParse(row["BeginDate"].ToString(), out DateTime BeginDate))
                {
                    return(new WxResponse(0, "请选择来访时间", null).toJson());
                }
                if (!row.Table.Columns.Contains("EndDate") || !DateTime.TryParse(row["EndDate"].ToString(), out DateTime EndDate))
                {
                    return(new WxResponse(0, "请选择来访时间", null).toJson());
                }
                DateTime DateNow = DateTime.Now;
                if (DateNow.CompareTo(BeginDate) > 0)
                {
                    return(new WxResponse(0, "请重新选择正确的来访时间", null).toJson());
                }
                if (BeginDate.CompareTo(EndDate) > 0)
                {
                    return(new WxResponse(0, "请重新选择正确的来访时间", null).toJson());
                }
                string CommID = string.Empty;
                if (row.Table.Columns.Contains("CommID"))
                {
                    CommID = row["CommID"].ToString();
                }
                if (string.IsNullOrEmpty(CommID))
                {
                    return(new WxResponse(0, "请选择默认房屋(1001)", null).toJson());
                }
                string RoomID = string.Empty;
                if (row.Table.Columns.Contains("RoomID"))
                {
                    RoomID = row["RoomID"].ToString();
                }
                if (string.IsNullOrEmpty(RoomID))
                {
                    return(new WxResponse(0, "请选择默认房屋(1002)", null).toJson());
                }
                #endregion

                using (IDbConnection erpConn = new SqlConnection(erpConnStr))
                {
                    erpConn.Open();
                    var trans = erpConn.BeginTransaction();
                    try
                    {
                        dynamic RoomInfo = erpConn.QueryFirstOrDefault("SELECT CommName, RoomSign, RoomName FROM view_HSPR_Room_Filter WITH(NOLOCK) WHERE ISNULL(IsDelete, 0) = 0 AND CommID = @CommID AND RoomID = @RoomID", new { CommID, RoomID }, trans);
                        if (null == RoomInfo)
                        {
                            return(new WxResponse(0, "请选择默认房屋(1003)", null).toJson());
                        }
                        string CommName = Convert.ToString(RoomInfo.CommName);
                        string RoomSign = Convert.ToString(RoomInfo.RoomSign);
                        string RoomName = Convert.ToString(RoomInfo.RoomName);
                        string RecordID = Guid.NewGuid().ToString();
                        // 只负责保存到数据库以及发送短信,剩下的群组创建由同步程序执行
                        if (erpConn.Execute("INSERT INTO Tb_HSPR_Entrance_Group_Visitor_Record(CommID, RoomID, MemberName, MemberMobile, MemberType, BeginDate, EndDate, RecordID) VALUES(@CommID, @RoomID, @MemberName, @MemberMobile, @MemberType, @BeginDate, @EndDate, @RecordID)", new { CommID, RoomID, MemberName, MemberMobile, MemberType, BeginDate, EndDate, RecordID }, trans) <= 0)
                        {
                            trans.Rollback();
                            return(new WxResponse(0, "保存失败,请重试", null).toJson());
                        }
                        string Content = $"(访客预约)尊敬的{MemberName},{CommName}-{RoomSign}欢迎您于{BeginDate:MM月dd日HH时mm分}来访,点击http://wx.hoppowy.com/moredian/invite/{RecordID}上传人脸";
                        int    result  = SendShortMessage(MemberMobile, Content, out string errMsg, Convert.ToInt32(CorpID));
                        if (result != 0)
                        {
                            trans.Rollback();
                            GetLog().Warn($"短信发送失败(Mobile={MemberMobile},Content={Content},msg={errMsg})");
                            return(new WxResponse(0, "操作失败,请重试", null).toJson());
                        }
                        GetLog().Warn($"短信发送成功(Mobile={MemberMobile},Content={Content})");
                        trans.Commit();
                        return(new WxResponse(200, "操作成功", null).toJson());
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        GetLog().Error(ex.Message + Environment.CommandLine + ex.StackTrace);
                        return(new WxResponse(0, "操作失败,请重试", null).toJson());
                    }
                }
            }
            catch (Exception ex)
            {
                GetLog().Error(ex.Message + Environment.CommandLine + ex.StackTrace);
                return(new WxResponse(0, "响应异常", null).toJson());
            }
        }
예제 #3
0
        //var model = new ValidationViewModel
        //modle
        public string this[string columnName]
        {
            get
            {
                string result = null;
                if (columnName == "FirstName")
                {
                    if (string.IsNullOrEmpty(FirstName))
                    {
                        result = "FirstName is a mandatory field!";
                    }
                }
                if (columnName == "LastName")
                {
                    if (string.IsNullOrEmpty(LastName))
                    {
                        result = "LastName is a mandatory field!";
                    }
                }

                if (columnName == "Email")
                {
                    if (string.IsNullOrEmpty(Email))
                    {
                        result = "Email a mandatory field!";
                    }
                    else if (!EmailValidation.IsValidEmailAddress(Email))
                    {
                        result = "The emails address is not valid!!";
                    }
                }

                if (columnName == "Phone")
                {
                    if (string.IsNullOrEmpty(Phone))
                    {
                        result = "Phone is a mandatory field!";
                    }
                }

                if (columnName == "Dob")
                {
                    DateTime hundredYearsPast = DateTime.Now.AddYears(-100);

                    if (Dob.Equals(null))
                    {
                        result = "Dob is a mandatory field!";
                    }

                    else if (Dob.CompareTo(DateTime.Now) > 0)
                    {
                        result = "Dob should be in the past!";
                    }
                    //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1)
                    else if (Dob < hundredYearsPast)
                    {
                        result = "Dob not should be in the 100+ years past";
                    }
                }

                if (columnName == "WorkDate")
                {
                    DateTime tenYearsPast = DateTime.Now.AddYears(-10);

                    if (WorkDate.Equals(null))
                    {
                        result = "WorkDate is a mandatory field!";
                    }

                    else if (WorkDate.CompareTo(DateTime.Now) >= 0)
                    {
                        result = "WorkDate should be in the past or Today!";
                    }
                    //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1)
                    else if (WorkDate < tenYearsPast)
                    {
                        result = "WorkDate should not be in 10+ year past";
                    }
                }

                if (columnName == "Hours")
                {
                    if (Hours <= 0 || Hours > 24)
                    {
                        result = "Hours must be between 0 and 24";
                    }
                }

                if (columnName == "BeginDate")
                {
                    DateTime tenYearsPast = DateTime.Now.AddYears(-10);

                    if (BeginDate.Equals(null))
                    {
                        result = "BeginDate is a mandatory field to Calculate TotalHours for the period!";
                    }

                    else if (BeginDate.CompareTo(DateTime.Now) >= 0)
                    {
                        result = "BeginDate should be in the past or Today!";
                    }
                    //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1)
                    else if (BeginDate < tenYearsPast)
                    {
                        result = "BeginDate should not be in 10+ year past";
                    }
                }

                if (columnName == "EndDate")
                {
                    DateTime tenYearsPast = DateTime.Now.AddYears(-10);

                    if (EndDate.Equals(null))
                    {
                        result = "EndDate is a mandatory field to Calculate TotalHours for the period!";
                    }

                    else if (EndDate.CompareTo(DateTime.Now) >= 0)
                    {
                        result = "EndDate should be in the past or Today!";
                    }
                    //else if(DateTime.Compare(hundredYearsPast, DateTime.Now.AddYears(-100))< 1)
                    else if (EndDate < tenYearsPast)
                    {
                        result = "EndDate should not be in 10+ year past";
                    }
                }

                return(result);
            }
        }