/// <summary>
        /// 获取会员佣金比例
        /// </summary>
        /// <param name="loginId">登录ID</param>
        /// <param name="orgID">组织机构ID</param>
        /// <returns>OrgTicketUrlInfo</returns>
        public CommissionRatioSetInfo GetCommissionRatio(string loginId, string orgID, bool type)
        {
            var info = new CommissionRatioSetInfo();
            DbDataReader dbreader = null;
            var tdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期
                if (!ComFunction.ExistUserLoginID(loginId, ref tdUser))
                {
                    info.Result = false;
                    info.Desc = ResCode.UL003Desc;
                    return info;
                }
                #endregion

                string sql;
                sql = string.Format(@"SELECT [ID],[OrgID] ,[Ratio1] ,[Ratio2] ,[Ratio3] FROM [Trade_CommissionRatioSet] where OrgID='{0}'", orgID);
                if (type)
                    sql = string.Format(@"SELECT [ID],[OrgID] ,[Ratio1] ,[Ratio2] ,[Ratio3] FROM [Trade_CommissionRatioSet] where OrgID='{0}'", "system");
                dbreader = DbHelper2.ExecuteReader(sql);
                while (dbreader.Read())
                {
                    info.ID = DBNull.Value != dbreader["ID"] ? dbreader["ID"].ToString() : string.Empty;
                    info.OrgID = DBNull.Value != dbreader["OrgID"] ? dbreader["OrgID"].ToString() : string.Empty;
                    info.Ratio1 = DBNull.Value != dbreader["Ratio1"] ? Convert.ToDouble(dbreader["Ratio1"]) : 0;
                    info.Ratio2 = DBNull.Value != dbreader["Ratio2"] ? Convert.ToDouble(dbreader["Ratio2"]) : 0;
                    info.Ratio3 = DBNull.Value != dbreader["Ratio3"] ? Convert.ToDouble(dbreader["Ratio3"]) : 0;
                }
                if (string.IsNullOrEmpty(info.ID))
                {
                    string sql2 = string.Format(@"SELECT [ID],[OrgID] ,[Ratio1] ,[Ratio2] ,[Ratio3] FROM [Trade_CommissionRatioSet] where OrgID='{0}'", "system");
                    dbreader = DbHelper2.ExecuteReader(sql2);
                    while (dbreader.Read())
                    {
                        info.ID = DBNull.Value != dbreader["ID"] ? dbreader["ID"].ToString() : string.Empty;
                        info.OrgID = DBNull.Value != dbreader["OrgID"] ? dbreader["OrgID"].ToString() : string.Empty;
                        info.Ratio1 = DBNull.Value != dbreader["Ratio1"] ? Convert.ToDouble(dbreader["Ratio1"]) : 0;
                        info.Ratio2 = DBNull.Value != dbreader["Ratio2"] ? Convert.ToDouble(dbreader["Ratio2"]) : 0;
                        info.Ratio3 = DBNull.Value != dbreader["Ratio3"] ? Convert.ToDouble(dbreader["Ratio3"]) : 0;
                    }
                }
                info.Result = true;
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                info.Result = false;
                info.Desc = "加载异常,请联系管理员";
            }
            finally
            {
                if (null != dbreader)
                {
                    dbreader.Close();
                    dbreader.Dispose();
                }
            }
            return info;
        }
        /// <summary>
        /// 添加广告
        /// </summary>
        /// <param name="loginId">登录标识</param>
        /// <param name="exp">体验券</param>
        /// <returns>ResultDesc</returns>
        public ResultDesc AddAdvert(string loginId, Advert exp)
        {
            ResultDesc rsdc = new ResultDesc();
            var tdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期
                if (!ComFunction.ExistUserLoginID(loginId, ref tdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                #endregion
                var sqlList = new List<string>();
                sqlList.Add(string.Format("INSERT INTO [Trade_Advert]([ID]  ,[Url] ,[Creator] ,[CreateDate],[Status] ,[Remark],[Name]) VALUES ('{0}' ,'{1}' ,'{2}' ,'{3}' ,{4} ,'{5}','{6}')",
                    exp.ID, exp.Url, exp.Creator, exp.CreateDate, Convert.ToByte(exp.Status), exp.Remark, exp.Name));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "添加广告出错!";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "添加广告成功!";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "";
            }
            return rsdc;
        }
 /// <summary>
 /// 新增组织机构
 /// </summary>
 /// <param name="loginId">登录ID</param>
 /// <param name="orgEntity"></param>
 /// <returns></returns>
 public EntityBase AddOrg(string loginId, OrgEntity orgEntity)
 {
     TradeUser TdUser = new TradeUser();
     if (ComFunction.ExistUserLoginID(loginId, ref TdUser) == false)
     {
         return entityBase;
     }
     UserLogEntity userLogEntity = new UserLogEntity();
     userLogEntity.Account = TdUser.Account;
     userLogEntity.DESC = string.Format(@"后台新增组织机构;{0}", orgEntity.OrgName);
     userLogEntity.UserType = (int)TdUser.UType;
     //检测使用组织编码作为默认组织账户时,组织账户是否已经存在
     if(ComFunction.TradeAccountExist(orgEntity.TelePhone))
     {
         entityBase.Result = false;
         entityBase.Desc = string.Format("新增失败,已存在组织账户{0}!", orgEntity.TelePhone);
         return entityBase;
     }
     if (ComFunction.IsExitOrgName(orgEntity.OrgName, orgEntity.TelePhone) >= 1)
     {
         entityBase.Result = false;
         entityBase.Desc = "新增失败,存在相同的机构名称或组织编码!";
         return entityBase;
     }
     if (string.IsNullOrEmpty(orgEntity.ParentOrgId))
     {
         orgEntity.ParentOrgId = "";
         orgEntity.ParentOrgName = "";
     }
     YicelTransaction tran = new YicelTransaction();
     try
     {
         string ipmac = string.Empty;
         if (!string.IsNullOrEmpty(TdUser.Ip))
         {
             ipmac += string.Format("IP={0},", TdUser.Ip);
         }
         if (!string.IsNullOrEmpty(TdUser.Mac))
         {
             ipmac += string.Format("MAC={0},", TdUser.Mac);
         }
         tran.BeginTransaction();
         ComFunction.AddOrg(orgEntity, tran);
         ComFunction.CreateLogEx(userLogEntity,ipmac, tran);
         tran.Commit();
         entityBase.Result = true;
         entityBase.Desc = "组织机构新增成功";
     }
     catch (Exception ex)
     {
         tran.Rollback();
         entityBase.Result = false;
         entityBase.Desc = "组织机构新增失败";
         SetException("组织机构新增失败,原因:", ex);
     }
     return entityBase;
 }
        /// <summary>
        /// 华夏银行签约,他行开户
        /// </summary>
        /// <param name="userid">用户ID</param>
        /// <param name="OpenBank">他行开户信息</param>
        /// <returns>签约结果</returns>
        public ResultDesc ContactToHuaxiaOhterBank(string userid, OpenBankInfo OpenBank)
        {
            ResultDesc rsdc = new ResultDesc();

            TradeUser TdUser = new TradeUser();
            try
            {
                #region 判断用户ID是否为空

                if(string.IsNullOrEmpty(userid))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "用户ID不能为空";
                    return rsdc;
                }
                #endregion
                TdUser = ComFunction.GetTradeUserByUserid(userid);
                //Fundinfo Fdinfo = ComFunction.GetFdinfo(string.Format("select * from Trade_FundInfo where userid='{0}' and state<>'4'", userid));
                string codeDesc = string.Empty;
                string subUser = string.Empty;
                //调用华夏银行子帐户同步接口
                if (!ComFunction.ContactToHuaxiaOhterBank(TdUser, OpenBank, ref codeDesc, ref subUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = string.Format("华夏银行签约,他行开户时,失败,华夏返回消息:{0}", codeDesc);
                    return rsdc;
                }

                //SQL语句
                List<string> sqlList = new List<string>();
                string sql1 = string.Format("update Trade_FundInfo set state='{0}',ConBankType='1',ConTime='{1}',BankAccount='{2}',AccountName='{3}',BankCard='{4}',OpenBank='{5}',OpenBankAddress='{6}',subUser='******' where userid='{7}' and state<>'{8}'",
                    2, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), OpenBank.BankAccount, OpenBank.AccountName, OpenBank.BankCard, OpenBank.OpenBank, OpenBank.OpenBankAddress, userid, 4, subUser);
                sqlList.Add(sql1);//0代表未签约 1表示审核中 2表示签约成功 3 表示失败 4表示已解约

                if (!ComFunction.SqlTransaction(sqlList))
                {
                     LogNet4.WriteMsg(string.Format("华夏银行签约,他行开户成功,但是SQL语句执行失败,SQL语句是:{0}",sql1));
                }
                rsdc.Result = true;
                rsdc.Desc = "华夏银行签约,他行开户时,成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "华夏银行签约,他行开户时,失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 普通用户转经纪人
        /// </summary>
        /// <param name="loginId">登录ID</param>
        /// <param name="wUserId">微交易用户ID</param>
        /// <returns>ResultDesc</returns>
        public ResultDesc BecomeEconomicMan(string loginId, string wUserId)
        {
            var rsdc = new ResultDesc();
            var tdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期
                if (!ComFunction.ExistUserLoginID(loginId, ref tdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }

                #endregion
                string operUser = tdUser.Account;//操作人
                var sqlList = new List<string>();
                string uSql = string.Format(@"update Base_WUser set AccountType='4' where WUserId='{0}'", wUserId);
                sqlList.Add(uSql);

                //添加操作记录
                string ipmac = ComFunction.GetIpMac(tdUser.Ip, tdUser.Mac);
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)tdUser.UType, string.Format("{0}转经纪人", ipmac)));
                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "转经纪人出错!";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "转经纪人成功!";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "服务器返回错误";
            }
            return rsdc;
        }
        /// <summary>
        /// 解约处理-拒绝
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <param name="LoginId"></param>
        /// <returns></returns>
        public ResultDesc RefusedJieYue(int ApplyId, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            int result = 0;
            System.Data.Common.DbParameter OutputParam = DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                "@Result", DbParameterType.Int, result, ParameterDirection.Output);
            try
            {
                TradeUser TdUser = new TradeUser();

                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion
                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();
                strbld.AppendFormat("update Trade_JieYue set ");

                strbld.AppendFormat("State=2, SHTime='{0}' ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                strbld.AppendFormat(" where ApplyId={0}", ApplyId);
                sqlList.Add(strbld.ToString());
                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}解约处理-拒绝:ApplyId={0}", ApplyId, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "操作失败";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "操作成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "操作失败!";
            }
            return rsdc;
        }
        /// <summary>
        /// 新增交易用户
        /// </summary>
        /// <param name="TdUser">用户信息</param>
        /// <param name="Fdinfo">资金信息</param>
        /// <param name="UType">用户类型</param>
        /// <param name="LoginId">登陆标识</param>
        /// <returns>结果描述</returns>
        public ResultDesc AddTradeUserEx(TradeUser TdUser, Fundinfo Fdinfo, UserType UType, string LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            TradeUser RefTdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref RefTdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                #endregion

                if (UserType.NormalType == RefTdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = RefTdUser.Account;

                if (string.IsNullOrEmpty(TdUser.Account))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "用户账号不能为空";
                    return rsdc;
                }
                if (string.IsNullOrEmpty(TdUser.LoginPwd))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "用户密码不能为空";
                    return rsdc;
                }
                if (UserType.NormalType == UType && string.IsNullOrEmpty(TdUser.CashPwd))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "资金密码不能为空";
                    return rsdc;
                }
                if (string.IsNullOrEmpty(TdUser.CardNum))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "证件号码不能为空";
                    return rsdc;
                }
                if (string.IsNullOrEmpty(TdUser.UserID))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "用户ID不能为空";
                    return rsdc;
                }
                string OrgId = string.Empty;

                if (!string.IsNullOrEmpty(TdUser.OrgName))
                {
                    //判断组织ID是否存在
                    if (!ComFunction.ExistOrgName(TdUser.OrgName, ref OrgId))
                    {
                        rsdc.Result = false;
                        rsdc.Desc = "你所指定的组织名称不存在";
                        return rsdc;
                    }

                }

                bool tradeAccountExist = false;
                //判断用户账号 或 证件号码是否已经被使用
                if (ComFunction.CardNumIsExist(TdUser.Account, TdUser.CardNum, ref tradeAccountExist))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "证件号码已经被使用";
                    return rsdc;
                }
                if (tradeAccountExist)
                {
                    rsdc.Result = false;
                    rsdc.Desc = string.Format("账号{0}已经存在", TdUser.Account);
                    return rsdc;
                }

                if (UserType.OrgType == UType && !string.IsNullOrEmpty(OrgId) && !string.IsNullOrEmpty(TdUser.BindAccount))
                {
                    if (!ComFunction.ExistNormalAccount(TdUser.BindAccount, OrgId))
                    {
                        rsdc.Result = false;
                        rsdc.Desc = "你所指定的绑定帐号不存在";
                        return rsdc;
                    }
                }

                int ute = (int)UType;

                //SQL语句
                List<string> sqlList = new List<string>();

                StringBuilder strbld = new StringBuilder();
                //string userid = System.Guid.NewGuid().ToString().Replace("-", "");
                string strdt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                string ipmac = ComFunction.GetIpMac(RefTdUser.Ip, RefTdUser.Mac);
                //TdUser.OrderUnit = 1;//手数单位默认为1
                if (UserType.NormalType == UType)
                {
                    //构造新增基本用户信息的sql语句
                    strbld.AppendFormat(@"insert into Base_User([userId],[userName],[status],[Accounttype],[CorporationName],
                        [Account],[LoginPwd],[cashPwd],[CardType],[CardNum],[OrgId],[PhoneNum],[TelNum],[Email],[LinkMan],[LinkAdress],
                        [OrderPhone],[sex],[OpenMan],[OpenTime],[LastUpdateTime],[LastUpdateID],[LoginID],[Ip],[Mac],[Online],[MinTrade],
                        [OrderUnit],[MaxTrade],[PermitRcash],[PermitCcash],[PermitDhuo],[PermitHshou],[PermitRstore],[PermitDelOrder],
                        [UserType]) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',", TdUser.UserID, string.IsNullOrEmpty(TdUser.UserName) ? string.Empty : TdUser.UserName,
                                                                                  TdUser.Status, TdUser.AccountType, string.IsNullOrEmpty(TdUser.CorporationName) ? string.Empty : TdUser.CorporationName, TdUser.Account, Des3.Des3EncodeCBC(TdUser.LoginPwd), Des3.Des3EncodeCBC(TdUser.CashPwd));
                    strbld.AppendFormat("'{0}','{1}','{2}','{3}','{4}','{5}','{6}',", TdUser.CardType, TdUser.CardNum, string.IsNullOrEmpty(OrgId) ? string.Empty : OrgId,
                        TdUser.PhoneNum, TdUser.TelNum, TdUser.Email, TdUser.LinkMan);
                    strbld.AppendFormat("'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',", TdUser.LinkAdress, TdUser.OrderPhone, TdUser.Sex, TdUser.OpenMan, strdt, strdt, operUser, string.Empty);
                    strbld.AppendFormat("'{0}','{1}',{2},{3},{4},{5},", string.Empty, string.Empty, 0, TdUser.MinTrade, TdUser.OrderUnit, TdUser.MaxTrade);
                    strbld.AppendFormat("{0},{1},{2},{3},{4},{5},{6})", TdUser.PermitRcash ? 1 : 0, TdUser.PermitCcash ? 1 : 0, TdUser.PermitDhuo ? 1 : 0, TdUser.PermitHshou ? 1 : 0, TdUser.PermitRstore ? 1 : 0, TdUser.PermitDelOrder ? 1 : 0, ute);
                    sqlList.Add(strbld.ToString());

                    //构造新增用户资金信息的sql语句
                    sqlList.Add(string.Format("insert into Trade_FundInfo([userId],[state],[money],[OccMoney],[frozenMoney],[BankAccount],[AccountName],[BankCard],[CashUser],[SubUser],[ConBankType],[OpenBank],[OpenBankAddress],[SameBank]) values('{0}','{1}',{2},{3},{4},'{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}',{13})",
                        TdUser.UserID, 0, 0, 0, 0, string.Empty, TdUser.UserName, Fdinfo.BankCard, System.Guid.NewGuid().ToString().Replace("-", ""), string.Empty, Fdinfo.ConBankType, Fdinfo.OpenBank, string.Empty, 0));
                    //添加默认分组
                    string UserGroupId = ComFunction.GetUserGroupId();
                    if (!string.IsNullOrEmpty(UserGroupId))
                    {
                        sqlList.Add(string.Format("insert into Trade_User_Group(UserId, UserGroupId) values('{0}','{1}') ", TdUser.UserID, UserGroupId));
                    }
                    //添加操作记录
                    sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)RefTdUser.UType, string.Format("{1}新增账号{0}", TdUser.Account, ipmac)));
                }
                else if (UserType.AdminType == UType)
                {
                    //构造新增管理员信息的sql语句
                    strbld.AppendFormat(@"insert into Base_User([userId],[userName],[status],[Accounttype],[Account],[LoginPwd],
                                        [CardType],[CardNum],[PhoneNum],[TelNum],[Email],[LinkAdress],[sex],[OpenTime],
                                        [LastUpdateTime],[LastUpdateID],[Online],[UserType]) values('{0}','{1}','{2}','{3}','{4}','{5}',",
                                         TdUser.UserID, string.IsNullOrEmpty(TdUser.UserName) ? string.Empty : TdUser.UserName,
                                         TdUser.Status, 0, TdUser.Account, Des3.Des3EncodeCBC(TdUser.LoginPwd));
                    strbld.AppendFormat("'{0}','{1}','{2}','{3}','{4}',",
                                        1, TdUser.CardNum, TdUser.PhoneNum, TdUser.TelNum, TdUser.Email);
                    strbld.AppendFormat("'{0}','{1}','{2}','{3}','{4}',{5},{6})",
                                        TdUser.LinkAdress, TdUser.Sex, strdt, strdt, operUser, 0, ute);
                    sqlList.Add(strbld.ToString());

                    //添加操作记录
                    sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)RefTdUser.UType, string.Format("{1}新增管理员{0}", TdUser.Account, ipmac)));
                }
                else if (UType == UserType.OrgType)
                {
                    //构造新增组织用户信息的sql语句
                    strbld.AppendFormat(@"insert into Base_User([userId],[userName],[status],[Accounttype],[Account],[LoginPwd],
                                        [CardType],[CardNum],[OrgId],[PhoneNum],[TelNum],[Email],[LinkAdress],[sex],[OpenTime],
                                        [LastUpdateTime],[LastUpdateID],[Online],[UserType],[BindAccount])
                                        values('{0}','{1}','{2}','{3}','{4}','{5}',",
                                        TdUser.UserID, string.IsNullOrEmpty(TdUser.UserName) ? string.Empty : TdUser.UserName,
                                        TdUser.Status, 1, TdUser.Account, Des3.Des3EncodeCBC(TdUser.LoginPwd));
                    strbld.AppendFormat("'{0}','{1}','{2}','{3}','{4}','{5}',", TdUser.CardType, TdUser.CardNum, string.IsNullOrEmpty(OrgId) ? string.Empty : OrgId,
                        TdUser.PhoneNum, TdUser.TelNum, TdUser.Email);
                    strbld.AppendFormat("'{0}','{1}','{2}','{3}','{4}',{5},{6},'{7}')", TdUser.LinkAdress, TdUser.Sex, strdt, strdt, operUser, 0, ute, string.IsNullOrEmpty(TdUser.BindAccount) ? string.Empty : TdUser.BindAccount);
                    sqlList.Add(strbld.ToString());

                    //添加操作记录
                    sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)RefTdUser.UType, string.Format("{1}新增组织用户{0}", TdUser.Account, ipmac)));

                }

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "新增用户出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "新增用户成功";

            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "新增用户失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 解约处理-审核
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <param name="userid"></param>
        /// <param name="LoginId"></param>
        /// <returns></returns>
        public ResultDesc ProcessJieYue(int ApplyId, string userid, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion
                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();
                strbld.AppendFormat("update Trade_JieYue set ");

                strbld.AppendFormat("State=1, SHTime='{0}' ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                strbld.AppendFormat(" where ApplyId={0}", ApplyId);
                sqlList.Add(strbld.ToString());
                //通过审核 需要把Trade_fundinfo表的state状态改为0 并且清空持卡人,银行卡号,开户行
                sqlList.Add(string.Format("update trade_fundinfo set state='0',AccountName='',BankCard='',OpenBank='' where userid='{0}'", userid));
                //sqlList.Add(string.Format("update trade_fundinfo set state='0' where userid='{0}'", userid));//不清空持卡人,银行卡号,开户行
                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}解约处理-审核:ApplyId={0}", ApplyId, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "审核失败";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "审核成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "审核失败!";
            }
            return rsdc;
        }
        /// <summary>
        /// 拒绝出金
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <param name="LoginId"></param>
        /// <returns></returns>
        public ResultDesc RefusedChuJin(int ApplyId, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            int result = 0;
            System.Data.Common.DbParameter OutputParam = DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                "@Result", DbParameterType.Int, result, ParameterDirection.Output);
            try
            {
                TradeUser TdUser = new TradeUser();

                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion
                DbHelper.RunProcedureExecuteSql("Proc_RefusedChuJin",
                   new System.Data.Common.DbParameter[]{
                        DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                 "@ApplyID", DbParameterType.Int, ApplyId, ParameterDirection.Input),
                    DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                 "@OperUser", DbParameterType.String, operUser, ParameterDirection.Input),
                    OutputParam});
                result = Convert.ToInt32(OutputParam.Value);
                if (0 == result)
                {
                    rsdc.Result = false;
                    rsdc.Desc = "操作失败";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "操作成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "操作失败!";
            }
            return rsdc;
        }
        /// <summary>
        /// 签约华夏银行 本行开户
        /// </summary>
        /// <param name="TdUser">用户信息</param>
        /// <param name="codeDesc">签约结果代码描述</param>
        /// <returns>成功返回true 失败返回fasle</returns>
        public static bool ContactToHuaxiaSelfBank(TradeUser TdUser, ref string codeDesc)
        {
            bool IsSuc = false;
            IntersServerImplClient ic = new IntersServerImplClient();
            try
            {
                StringBuilder inXml = new StringBuilder();
                inXml.Append("<HXBB2B>");
                inXml.Append("<MessageData>");

                inXml.Append("<Base>");
                inXml.Append("<Version>1.0</Version>");
                inXml.Append("<SignFlag>0</SignFlag>");
                inXml.Append("<Language>GB2312</Language>");
                inXml.Append("</Base>");

                inXml.Append("<ReqHeader>");
                inXml.AppendFormat("<ClientTime>{0}</ClientTime>", DateTime.Now.ToString("yyyyMMddHHmmss"));
                inXml.Append("<MerchantNo>600014</MerchantNo>");
                inXml.Append("</ReqHeader>");

                inXml.Append("<DataBody>");
                inXml.AppendFormat("<MerTxSerNo>{0}</MerTxSerNo>", TdUser.CashUser);
                inXml.Append("<TrnxCode>DZ010</TrnxCode>");
                inXml.Append("<AccountInfos>");
                inXml.Append("<AccountInfo>");

                inXml.Append("<AccountNo></AccountNo>");
                inXml.AppendFormat("<MerAccountNo>{0}</MerAccountNo>", GetTanUser(TdUser.TanUser));
                inXml.AppendFormat("<AccountName>{0}</AccountName>", TdUser.UserName);
                inXml.AppendFormat("<AccountProp>{0}</AccountProp>", "0" == TdUser.AccountType ? 1 : 0);//华夏银行接口中,0表示企业1表示个人
                inXml.Append("<Amt></Amt>");//总余额
                inXml.Append("<AmtUse></AmtUse>");//可用余额
                inXml.AppendFormat("<PersonName>{0}</PersonName>", string.IsNullOrEmpty(TdUser.LinkMan) ? string.Empty : TdUser.LinkMan);
                inXml.AppendFormat("<OfficeTel>{0}</OfficeTel>", string.IsNullOrEmpty(TdUser.TelNum) ? string.Empty : TdUser.TelNum);
                inXml.AppendFormat("<MobileTel>{0}</MobileTel>", string.IsNullOrEmpty(TdUser.PhoneNum) ? string.Empty : TdUser.PhoneNum);
                inXml.AppendFormat("<Addr>{0}</Addr>", string.IsNullOrEmpty(TdUser.LinkAdress) ? string.Empty : TdUser.LinkAdress);

                inXml.Append("</AccountInfo>");
                inXml.Append("</AccountInfos>");
                inXml.Append("</DataBody>");

                inXml.Append("</MessageData>");
                inXml.Append("</HXBB2B>");
                com.individual.helper.LogNet4.WriteMsg("华夏银行本行签约,请求的Xml报文:" + inXml.ToString());
                string outXml = ic.Process(inXml.ToString());
                com.individual.helper.LogNet4.WriteMsg("华夏银行本行签约,响应的Xml报文:" + outXml);
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(outXml);
                if (HuaxiaSuc == xmldoc.SelectSingleNode("HXBB2B/MessageData/ResHeader/Status/Code").InnerText)
                {
                    IsSuc = true;
                }
                codeDesc = xmldoc.SelectSingleNode("HXBB2B/MessageData/ResHeader/Status/Message").InnerText;
                ic.Close();
            }
            catch (Exception ex)
            {
                ic.Abort();
                throw new Exception(ex.Message, ex);
            }

            return IsSuc;
        }
        /// <summary>
        /// 修改过滤Mac
        /// </summary>
        /// <param name="TdMac">过滤Mac信息</param>
        /// <param name="LoginId">管理员登陆标识</param>
        /// <returns>修改结果</returns>
        public ResultDesc ModifyTradeMac(TradeMac TdMac, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;

                #endregion
                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();
                strbld.AppendFormat("update Trade_Mac set ");

                strbld.AppendFormat("Mac='{0}',", TdMac.MAC);
                strbld.AppendFormat("[desc]='{0}'", TdMac.Desc);
                strbld.AppendFormat(" where ID='{0}'", TdMac.ID);
                sqlList.Add(strbld.ToString());

                //添加操作记录
                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}修改过滤Mac:{0}", TdMac.ID, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "修改过滤Mac出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "修该过滤Mac成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "修改过滤Mac失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 获取交易用户信息列表
        /// </summary>
        /// <param name="sql">查询SQL</param>
        /// <returns>用户信息列表</returns>
        public static List<TradeUser> GetTdUserList(string sql)
        {
            SqlConnection sqlconn = null;
            SqlCommand sqlcmd = null;
            SqlDataReader sqldr = null;
            List<TradeUser> list = new List<TradeUser>();

            try
            {
                sqlconn = new SqlConnection(SqlConnectionString);
                sqlconn.Open();
                sqlcmd = sqlconn.CreateCommand();
                sqlcmd.CommandText = sql;
                sqldr = sqlcmd.ExecuteReader();
                while (sqldr.Read())
                {
                    TradeUser TdUser = new TradeUser();
                    TdUser.UserName = System.DBNull.Value != sqldr["UserName"] ? sqldr["UserName"].ToString() : string.Empty;
                    TdUser.Status = System.DBNull.Value != sqldr["State"] ? sqldr["State"].ToString() : string.Empty;
                    TdUser.AccountType = System.DBNull.Value != sqldr["UserType"] ? sqldr["UserType"].ToString() : string.Empty;
                    TdUser.Account = System.DBNull.Value != sqldr["TradeAccount"] ? sqldr["TradeAccount"].ToString() : string.Empty;
                    TdUser.LoginPwd = System.DBNull.Value != sqldr["TradePwd"] ? Des3.Des3DecodeCBC(sqldr["TradePwd"].ToString()) : string.Empty;
                    TdUser.CashPwd = System.DBNull.Value != sqldr["CashPwd"] ? Des3.Des3DecodeCBC(sqldr["CashPwd"].ToString()) : string.Empty;
                    TdUser.CardType = System.DBNull.Value != sqldr["CardType"] ? sqldr["CardType"].ToString() : string.Empty;
                    TdUser.CardNum = System.DBNull.Value != sqldr["CardNum"] ? sqldr["CardNum"].ToString() : string.Empty;
                    TdUser.PhoneNum = System.DBNull.Value != sqldr["PhoneNum"] ? sqldr["PhoneNum"].ToString() : string.Empty;
                    TdUser.TelNum = System.DBNull.Value != sqldr["TelNum"] ? sqldr["TelNum"].ToString() : string.Empty;
                    TdUser.Email = System.DBNull.Value != sqldr["Email"] ? sqldr["Email"].ToString() : string.Empty;
                    TdUser.LinkMan = System.DBNull.Value != sqldr["LinkMan"] ? sqldr["LinkMan"].ToString() : string.Empty;
                    TdUser.LinkAdress = System.DBNull.Value != sqldr["LinkAdress"] ? sqldr["LinkAdress"].ToString() : string.Empty;
                    TdUser.Sex = System.DBNull.Value != sqldr["Sex"] ? sqldr["Sex"].ToString() : string.Empty;
                    TdUser.OpenMan = System.DBNull.Value != sqldr["OpenMan"] ? sqldr["OpenMan"].ToString() : string.Empty;
                    TdUser.OpenTime = System.DBNull.Value != sqldr["OpenTime"] ? Convert.ToDateTime(sqldr["OpenTime"]) : DateTime.MinValue;
                    TdUser.LastUpdateTime = System.DBNull.Value != sqldr["LastUpdateTime"] ? Convert.ToDateTime(sqldr["LastUpdateTime"]) : DateTime.MinValue;
                    TdUser.LastUpdateID = System.DBNull.Value != sqldr["LastUpdateID"] ? sqldr["LastUpdateID"].ToString() : string.Empty;

                    TdUser.Ip = System.DBNull.Value != sqldr["Ip"] ? sqldr["Ip"].ToString() : string.Empty;
                    TdUser.Mac = System.DBNull.Value != sqldr["Mac"] ? sqldr["Mac"].ToString() : string.Empty;
                    TdUser.LastLoginTime = System.DBNull.Value != sqldr["LastLoginTime"] ? Convert.ToDateTime(sqldr["LastLoginTime"]) : DateTime.MinValue;
                    TdUser.Online = System.DBNull.Value != sqldr["Online"] ? Convert.ToBoolean(sqldr["Online"]) : false;
                    TdUser.MinTrade = System.DBNull.Value != sqldr["MinTrade"] ? Convert.ToDouble(sqldr["MinTrade"]) : 0;
                    TdUser.OrderUnit = System.DBNull.Value != sqldr["OrderUnit"] ? Convert.ToDouble(sqldr["OrderUnit"]) : 0;
                    TdUser.MaxTrade = System.DBNull.Value != sqldr["MaxTrade"] ? Convert.ToDouble(sqldr["MaxTrade"]) : 0;
                    TdUser.PermitRcash = System.DBNull.Value != sqldr["PermitRcash"] ? Convert.ToBoolean(sqldr["PermitRcash"]) : false;
                    TdUser.PermitCcash = System.DBNull.Value != sqldr["PermitCcash"] ? Convert.ToBoolean(sqldr["PermitCcash"]) : false;
                    TdUser.PermitDhuo = System.DBNull.Value != sqldr["PermitDhuo"] ? Convert.ToBoolean(sqldr["PermitDhuo"]) : false;
                    TdUser.PermitHshou = System.DBNull.Value != sqldr["PermitHshou"] ? Convert.ToBoolean(sqldr["PermitHshou"]) : false;
                    TdUser.PermitRstore = System.DBNull.Value != sqldr["PermitRstore"] ? Convert.ToBoolean(sqldr["PermitRstore"]) : false;
                    TdUser.PermitDelOrder = System.DBNull.Value != sqldr["PermitDelOrder"] ? Convert.ToBoolean(sqldr["PermitDelOrder"]) : false;
                    TdUser.CorporationName = System.DBNull.Value != sqldr["CorporationName"] ? sqldr["CorporationName"].ToString() : string.Empty;
                    TdUser.OrderPhone = System.DBNull.Value != sqldr["OrderPhone"] ? sqldr["OrderPhone"].ToString() : string.Empty;

                    TdUser.BankState = System.DBNull.Value != sqldr["BankState"] ? sqldr["BankState"].ToString() : string.Empty;
                    TdUser.Money = System.DBNull.Value != sqldr["Money"] ? Convert.ToDouble(sqldr["Money"]) : 0;
                    TdUser.OccMoney = System.DBNull.Value != sqldr["OccMoney"] ? Convert.ToDouble(sqldr["OccMoney"]) : 0;
                    TdUser.FrozenMoney = System.DBNull.Value != sqldr["FrozenMoney"] ? Convert.ToDouble(sqldr["FrozenMoney"]) : 0;
                    TdUser.BankAccount = System.DBNull.Value != sqldr["BankAccount"] ? sqldr["BankAccount"].ToString() : string.Empty;
                    TdUser.AccountName = System.DBNull.Value != sqldr["AccountName"] ? sqldr["AccountName"].ToString() : string.Empty;
                    TdUser.BankCard = System.DBNull.Value != sqldr["BankCard"] ? sqldr["BankCard"].ToString() : string.Empty;

                    TdUser.SubUser = System.DBNull.Value != sqldr["SubUser"] ? sqldr["SubUser"].ToString() : string.Empty;
                    TdUser.TanUser = System.DBNull.Value != sqldr["TanUser"] ? sqldr["TanUser"].ToString() : string.Empty;
                    TdUser.ConBankType = System.DBNull.Value != sqldr["ConBankType"] ? sqldr["ConBankType"].ToString() : string.Empty;
                    TdUser.OpenBank = System.DBNull.Value != sqldr["OpenBank"] ? sqldr["OpenBank"].ToString() : string.Empty;
                    TdUser.OpenBankAddress = System.DBNull.Value != sqldr["OpenBankAddress"] ? sqldr["OpenBankAddress"].ToString() : string.Empty;

                    TdUser.OrgId = System.DBNull.Value != sqldr["AgentId"] ? sqldr["AgentId"].ToString() : string.Empty;
                    TdUser.CashUser = System.DBNull.Value != sqldr["CashUser"] ? sqldr["CashUser"].ToString() : string.Empty;
                    list.Add(TdUser);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (null != sqlconn)
                {
                    sqlconn.Close();
                }
                if (null != sqldr)
                {
                    sqldr.Close();
                }
            }
            return list;
        }
        /// <summary>
        /// 根据用户账号获取用户ID
        /// </summary>
        /// <param name="TradeAccount">用户账号</param>
        /// <param name="TdUser">用户信息</param>
        /// <returns>用户ID</returns>
        public static string GetUserId(string TradeAccount, ref TradeUser TdUser)
        {
            System.Data.Common.DbDataReader dbreader = null;
            string userid = string.Empty;
            try
            {
                string sql = "select OrgId, UserType, Account, MinTrade,OrderUnit,MaxTrade,PermitRcash,PermitCcash,PermitDhuo,PermitHshou,PermitRstore,PermitDelOrder,userId,CashPwd,LoginPwd from Base_User where  Account=@Account";

                dbreader = DbHelper.ExecuteReader(sql,
                    new System.Data.Common.DbParameter[] { DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type, "@Account", DbParameterType.String, TradeAccount, ParameterDirection.Input) });
                if (dbreader.Read())
                {
                    TdUser.OrgId = System.DBNull.Value != dbreader["OrgId"] ? dbreader["OrgId"].ToString() : string.Empty;
                    TdUser.UType = System.DBNull.Value != dbreader["UserType"] ? (UserType)(dbreader["UserType"]) : UserType.AdminType;
                    TdUser.Account = System.DBNull.Value != dbreader["Account"] ? dbreader["Account"].ToString() : string.Empty;
                    TdUser.MinTrade = System.DBNull.Value != dbreader["MinTrade"] ? Convert.ToDouble(dbreader["MinTrade"]) : 1;
                    TdUser.OrderUnit = System.DBNull.Value != dbreader["OrderUnit"] ? Convert.ToDouble(dbreader["OrderUnit"]) : 1;
                    TdUser.MaxTrade = System.DBNull.Value != dbreader["MaxTrade"] ? Convert.ToDouble(dbreader["MaxTrade"]) : 50;
                    TdUser.PermitRcash = System.DBNull.Value != dbreader["PermitRcash"] ? Convert.ToBoolean(dbreader["PermitRcash"]) : false;
                    TdUser.PermitCcash = System.DBNull.Value != dbreader["PermitCcash"] ? Convert.ToBoolean(dbreader["PermitCcash"]) : false;
                    TdUser.PermitDhuo = System.DBNull.Value != dbreader["PermitDhuo"] ? Convert.ToBoolean(dbreader["PermitDhuo"]) : false;
                    TdUser.PermitHshou = System.DBNull.Value != dbreader["PermitHshou"] ? Convert.ToBoolean(dbreader["PermitHshou"]) : false;
                    TdUser.PermitRstore = System.DBNull.Value != dbreader["PermitRstore"] ? Convert.ToBoolean(dbreader["PermitRstore"]) : false;
                    TdUser.PermitDelOrder = System.DBNull.Value != dbreader["PermitDelOrder"] ? Convert.ToBoolean(dbreader["PermitDelOrder"]) : false;
                    TdUser.LoginPwd = System.DBNull.Value != dbreader["LoginPwd"] ? dbreader["LoginPwd"].ToString() : string.Empty;
                    TdUser.CashPwd = System.DBNull.Value != dbreader["CashPwd"] ? dbreader["CashPwd"].ToString() : string.Empty;

                    userid = System.DBNull.Value != dbreader["userId"] ? dbreader["userId"].ToString() : string.Empty;
                    TdUser.UserID = userid;
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (null != dbreader)
                {
                    dbreader.Close();
                    dbreader.Dispose();
                }
            }
            return userid;
        }
        /// <summary>
        /// 2.3.4.2	添加客户组
        /// </summary>
        /// <param name="ugs"></param>
        /// <param name="LoginId"></param>
        /// <returns></returns>
        public ResultDesc AddUserGroups(UserGroups ugs, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;

                #endregion
                if (string.IsNullOrEmpty(ugs.UserGroupName))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "客户组名称不能为空";
                    return rsdc;
                }
                List<string> sqlList = new List<string>();
                sqlList.Add(string.Format(@"insert into Trade_UserGroups(UserGroupId, UserGroupName, IsDefaultGroup, AfterSecond, PlaceOrderSlipPoint,
                                FlatOrderSlipPoint, DelayPlaceOrder, DelayFlatOrder) values('{0}','{1}',{2},{3},{4},{5},{6},{7}) ",
                                ugs.UserGroupId, ugs.UserGroupName, ugs.IsDefaultGroup, ugs.AfterSecond, ugs.PlaceOrderSlipPoint,
                                ugs.FlatOrderSlipPoint, ugs.DelayPlaceOrder, ugs.DelayFlatOrder));
                if (1 == ugs.IsDefaultGroup)//如果新加的组为默认组时,需要把其他组全部修改为非默认组
                {
                    sqlList.Add(string.Format("update Trade_UserGroups set IsDefaultGroup=0 where UserGroupId<>'{0}'", ugs.UserGroupId));
                }
                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "添加客户组出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "添加客户组成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "添加客户组失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 2.3.4.5	添加客户到客户组
        /// </summary>
        /// <param name="account">客户账号</param>
        /// <param name="UserGroupId">客户组ID</param>
        /// <param name="LoginId"></param>
        /// <param name="tduser">添加成功后,返回的被添加的客户的信息</param>
        /// <returns></returns>
        public ResultDesc AddUserToUserGroups(string account, string UserGroupId, String LoginId, ref TradeUser tduser)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;

                #endregion
                List<string> sqlList = new List<string>();
                string UserId = ComFunction.GetUserId(account);
                if (string.IsNullOrEmpty(UserId))
                {
                    rsdc.Result = false;
                    rsdc.Desc = string.Format("帐号{0}不存在", account);
                    return rsdc;
                }
                if (ComFunction.ExistUserInTheGroup(UserId, UserGroupId))
                {
                    rsdc.Result = false;
                    rsdc.Desc = string.Format("帐号{0}已经添加到该组了", account);
                    return rsdc;
                }
                tduser = ComFunction.GetTradeUserByUserid(UserId);
                sqlList.Add(string.Format("delete from Trade_User_Group where UserId='{0}' ", UserId));
                sqlList.Add(string.Format("insert into Trade_User_Group(UserId, UserGroupId) values('{0}','{1}') ", UserId, UserGroupId));
                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "添加客户出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "添加客户成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "添加客户失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 修改交易设置
        /// </summary>
        /// <param name="TdSet">交易设置</param>
        /// <param name="LoginId">管理员登陆标识</param>
        /// <returns>修改结果</returns>
        public ResultDesc ModifyTradeSet(TradeSet TdSet, string LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion

                #region 验证数据
                if (!ComFunction.ValidateTradeSet(TdSet))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "值不正确";
                    return rsdc;
                }
                #endregion

                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();
                strbld.AppendFormat("update Trade_Set set ");

                strbld.AppendFormat("ObjName='{0}',", TdSet.ObjName);
                strbld.AppendFormat("ObjValue='{0}',", TdSet.ObjValue);
                strbld.AppendFormat("Remark='{0}' ", TdSet.Remark);
                strbld.AppendFormat("where ObjCode='{0}'", TdSet.ObjCode);
                sqlList.Add(strbld.ToString());
                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                //添加操作记录
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}修改交易设置,{0}", TdSet.ObjCode, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "修改交易设置出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "修该交易设置成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "修改交易设置失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 修改汇率和水
        /// </summary>
        /// <param name="TdRate">汇率和水信息</param>
        /// <param name="LoginId">管理员登陆标识</param>
        /// <returns>修改结果</returns>
        public ResultDesc ModifyTradeRate(TradeRate TdRate, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion
                List<string> sqlList = new List<string>();

                int result = ComFunction.ModifyWaterAndRate(TdRate);

                //添加操作记录
                if (1 == result)
                {
                    string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                    sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}修改汇率和水:{0}", TdRate.PriceCode, ipmac)));

                    if (!ComFunction.SqlTransaction(sqlList))
                    {
                        rsdc.Result = false;
                        rsdc.Desc = "修改汇率和水出错1";
                        return rsdc;
                    }
                    rsdc.Result = true;
                    rsdc.Desc = "修该汇率和水成功";
                }
                else
                {
                    rsdc.Result = false;
                    rsdc.Desc = "修改汇率和水出错2";
                    return rsdc;
                }
            }
            catch (Exception ex)
            {
                rsdc.Result = false;
                rsdc.Desc = "修改汇率和水失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 修改商品信息
        /// </summary>
        /// <param name="TdProduct">商品信息信息</param>
        /// <param name="LoginId">管理员登陆标识</param>
        /// <returns>修改结果</returns>
        public ResultDesc ModifyTradeProduct(TradeProduct TdProduct, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;

                #endregion
                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();
                strbld.AppendFormat("update Trade_Product set ");
                strbld.AppendFormat("ProductName='{0}',", TdProduct.ProductName);
                strbld.AppendFormat("Adjustbase={0},", TdProduct.Adjustbase);
                //strbld.AppendFormat("Adjustcount={0},", TdProduct.Adjustcount);
                strbld.AppendFormat("Expressionfee='{0}',", TdProduct.Expressionfee);
                strbld.AppendFormat("Holdbase={0},", TdProduct.Holdbase);
                strbld.AppendFormat("Lowerprice={0},", TdProduct.Lowerprice);
                strbld.AppendFormat("Maxprice={0},", TdProduct.Maxprice);
                strbld.AppendFormat("Maxtime={0},", TdProduct.Maxtime);
                strbld.AppendFormat("Minprice={0},", TdProduct.Minprice);
                //strbld.AppendFormat("Ordemoney={0},", TdProduct.Ordemoney);
                strbld.AppendFormat("Ordemoneyfee='{0}',", TdProduct.Ordemoneyfee);
                strbld.AppendFormat("Pricedot={0},", TdProduct.Pricedot);
                //strbld.AppendFormat("Sellfee='{0}',", TdProduct.Sellfee);
                strbld.AppendFormat("Sellstoragefee='{0}',", TdProduct.Sellstoragefee);
                strbld.AppendFormat("SetBase={0},", TdProduct.SetBase);
                strbld.AppendFormat("State='{0}',", TdProduct.State);
                strbld.AppendFormat("Unit={0},", TdProduct.Unit);
                strbld.AppendFormat("Valuedot={0},", TdProduct.Valuedot);
                strbld.AppendFormat("Buystoragefee='{0}',", TdProduct.Buystoragefee);
                strbld.AppendFormat("Pricecode='{0}',", TdProduct.Pricecode);
                //strbld.AppendFormat("Goodscode='{0}',", TdProduct.Goodscode);
                strbld.AppendFormat("starttime='{0}',", TdProduct.Starttime);
                strbld.AppendFormat("endtime='{0}'", TdProduct.Endtime);
                strbld.AppendFormat(" where Productcode='{0}'", TdProduct.Productcode);
                sqlList.Add(strbld.ToString());
                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                //添加操作记录
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}修改商品信息:{0}", TdProduct.ProductName, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "修改商品信息出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "修该商品信息成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "修改商品信息失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 新闻公告修改
        /// </summary>
        /// <param name="TdNews">新闻</param>
        /// <param name="LoginId">登陆标识</param>
        /// <returns>修改结果</returns>
        public ResultDesc ModifyTradeNews(TradeNews TdNews, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion
                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();
                strbld.AppendFormat("update Trade_News set ");

                strbld.AppendFormat("NewsContent='{0}',", TdNews.NewsContent);
                strbld.AppendFormat("NewsType={0},", (int)TdNews.NType);
                strbld.AppendFormat("Status={0},", (int)TdNews.Status);
                //  strbld.AppendFormat("PubTime='{0}',", TdNews.PubTime.ToString("yyyy-MM-dd"));
                strbld.AppendFormat("PubPerson='{0}',", TdNews.PubPerson);
                strbld.AppendFormat("OverView='{0}',", string.IsNullOrEmpty(TdNews.OverView) ? string.Empty : TdNews.OverView);

                strbld.AppendFormat("NewsTitle='{0}' ", TdNews.NewsTitle);
                strbld.AppendFormat(" where ID='{0}'", TdNews.ID);
                sqlList.Add(strbld.ToString());
                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                //添加操作记录
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}修改新闻公告,{0}", TdNews.ID, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "保存出错,请重试!";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "保存成功!";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "保存出错,请重试!";
            }
            return rsdc;
        }
        /// <summary>
        /// 添加交易设置
        /// </summary>
        /// <param name="TdSet">交易设置信息</param>
        /// <param name="LoginId">登陆标识</param>
        /// <returns>添加结果</returns>
        public ResultDesc AddTradeSet(TradeSet TdSet, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;

                #endregion
                List<string> sqlList = new List<string>();
                sqlList.Add(string.Format("insert into Trade_Set([ObjName],[ObjCode],[ObjValue],[Remark]) values('{0}','{1}','{2}','{3}')", TdSet.ObjName, TdSet.ObjCode, TdSet.ObjValue, TdSet.Remark));

                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}添加交易设置:{0}", TdSet.ObjCode, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "添加交易设置出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "添加交易设置成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "添加交易设置失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 添加体验券
        /// </summary>
        /// <param name="loginId">登录标识</param>
        /// <param name="exp">体验券</param>
        /// <returns>ResultDesc</returns>
        public ResultDesc AddExperience(string loginId, Experience exp)
        {
            ResultDesc rsdc = new ResultDesc();
            var tdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期
                if (!ComFunction.ExistUserLoginID(loginId, ref tdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                #endregion
                var sqlList = new List<string>();
                sqlList.Add(string.Format("INSERT INTO [TRADE_EXPERIENCE]([EX_NAME] ,[EX_TYPE] ,[EX_ANMOUNT] ,[EX_RECHARGE] ,[EX_NUM] ,[EX_STARTDATE] ,[EX_ENDDATE] ," +
                             "[EX_CREATID] ,[EX_EFFECTIVE],[EX_EFFECTIVETIME]) VALUES ('{0}',{1},{2},{3},{4},'{5}','{6}','{7}',{8},'{9}')",
                             exp.Name, exp.Type, exp.Annount, exp.Rceharge, exp.Num, exp.StartDate,
                             exp.EndDate, exp.CreatID, exp.Effective, exp.EffectiveTime
                    ));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "添加体验券出错!";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "添加体验券成功!";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "";
            }
            return rsdc;
        }
        /// <summary>
        /// 修改客户资料
        /// </summary>
        /// <param name="TdUser">用户信息</param>
        /// <param name="Fdinfo">资金信息</param>
        /// <param name="LoginId">登陆标识</param>
        /// <returns>修改结果</returns>
        public ResultDesc ModifyTradeUserEx(TradeUser TdUser, Fundinfo Fdinfo, string LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            TradeUser RefTdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期
                if (!ComFunction.ExistUserLoginID(LoginId, ref RefTdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }

                if (UserType.NormalType == RefTdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = RefTdUser.Account;
                #endregion

                if (string.IsNullOrEmpty(TdUser.Account))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "用户账号不能为空";
                    return rsdc;
                }
                if (string.IsNullOrEmpty(TdUser.LoginPwd))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "用户密码不能为空";
                    return rsdc;
                }

                //if (string.IsNullOrEmpty(TdUser.CardNum))
                //{
                //    rsdc.Result = false;
                //    rsdc.Desc = "证件号码不能为空";
                //    return rsdc;
                //}

                string OrgId = string.Empty;
                if (!string.IsNullOrEmpty(TdUser.OrgName))
                {
                    //判断组织ID是否存在
                    if (!ComFunction.ExistOrgName(TdUser.OrgName, ref OrgId))
                    {
                        rsdc.Result = false;
                        rsdc.Desc = "你所指定的组织名称不存在";
                        return rsdc;
                    }
                }
                //判断用户输入的证件号码在其他有效用户中是否已经被使用
                //if (ComFunction.CardNumIsExist(TdUser.Account, TdUser.CardNum))
                //{
                //    rsdc.Result = false;
                //    rsdc.Desc = "证件号码已经被使用";
                //    return rsdc;
                //}
                UserType Utype = ComFunction.GetUserType(TdUser.Account);
                //if (UserType.OrgType == Utype && !string.IsNullOrEmpty(OrgId) && !string.IsNullOrEmpty(TdUser.BindAccount))
                //{
                //    if (!ComFunction.ExistNormalAccount(TdUser.BindAccount, OrgId))
                //    {
                //        rsdc.Result = false;
                //        rsdc.Desc = "你所指定的绑定帐号不存在";
                //        return rsdc;
                //    }
                //}
                //if (UserType.NormalType == Utype && string.IsNullOrEmpty(TdUser.CashPwd))
                //{
                //    rsdc.Result = false;
                //    rsdc.Desc = "资金密码不能为空";
                //    return rsdc;
                //}
                //SQL语句
                List<string> sqlList = new List<string>();
                string userid = ComFunction.GetUserId(TdUser.Account);
                string strdt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                //构造修改用户信息的sql语句
                StringBuilder strbld = new StringBuilder();
                string ipmac = ComFunction.GetIpMac(RefTdUser.Ip, RefTdUser.Mac);
                //TdUser.OrderUnit = 1;//手数单位默认为1
                strbld.AppendFormat("update Base_User set ");

                strbld.AppendFormat("UserName='******',", string.IsNullOrEmpty(TdUser.UserName) ? string.Empty : TdUser.UserName);

                strbld.AppendFormat("CardNum='{0}',", string.IsNullOrEmpty(TdUser.CardNum) ? string.Empty : TdUser.CardNum);
                strbld.AppendFormat("OrgId='{0}',", string.IsNullOrEmpty(OrgId) ? string.Empty : OrgId);
                strbld.AppendFormat("PhoneNum='{0}',", string.IsNullOrEmpty(TdUser.PhoneNum) ? string.Empty : TdUser.PhoneNum);
                strbld.AppendFormat("TelNum='{0}',", string.IsNullOrEmpty(TdUser.TelNum) ? string.Empty : TdUser.TelNum);
                strbld.AppendFormat("Email='{0}',", string.IsNullOrEmpty(TdUser.Email) ? string.Empty : TdUser.Email);
                strbld.AppendFormat("LinkMan='{0}',", string.IsNullOrEmpty(TdUser.LinkMan) ? string.Empty : TdUser.LinkMan);
                strbld.AppendFormat("LinkAdress='{0}',", string.IsNullOrEmpty(TdUser.LinkAdress) ? string.Empty : TdUser.LinkAdress);
                strbld.AppendFormat("Sex='{0}',", string.IsNullOrEmpty(TdUser.Sex) ? "1" : TdUser.Sex);
                strbld.AppendFormat("[Status]='{0}',", string.IsNullOrEmpty(TdUser.Status) ? "0" : TdUser.Status);
                strbld.AppendFormat("LoginPwd='{0}',", Des3.Des3EncodeCBC(string.IsNullOrEmpty(TdUser.LoginPwd) ? "123456" : TdUser.LoginPwd));
                if (Utype == UserType.OrgType)
                {
                    strbld.AppendFormat("CardType='{0}',", string.IsNullOrEmpty(TdUser.CardType) ? "1" : TdUser.CardType);
                    strbld.AppendFormat("BindAccount='{0}',", string.IsNullOrEmpty(TdUser.BindAccount) ? string.Empty : TdUser.BindAccount);
                }
                else if (Utype == UserType.NormalType)
                {
                    strbld.AppendFormat("CardType='{0}',", string.IsNullOrEmpty(TdUser.CardType) ? "1" : TdUser.CardType);
                    strbld.AppendFormat("AccountType='{0}',", string.IsNullOrEmpty(TdUser.AccountType) ? "0" : TdUser.AccountType);
                    strbld.AppendFormat("OpenMan='{0}',", string.IsNullOrEmpty(TdUser.OpenMan) ? string.Empty : TdUser.OpenMan);
                    strbld.AppendFormat("OrderPhone='{0}',", string.IsNullOrEmpty(TdUser.OrderPhone) ? string.Empty : TdUser.OrderPhone);
                    strbld.AppendFormat("CashPwd='{0}',", Des3.Des3EncodeCBC(string.IsNullOrEmpty(TdUser.CashPwd) ? "123456" : TdUser.CashPwd));

                    strbld.AppendFormat("MinTrade={0},", TdUser.MinTrade);
                    strbld.AppendFormat("OrderUnit={0},", TdUser.OrderUnit);
                    strbld.AppendFormat("MaxTrade={0},", TdUser.MaxTrade);
                    strbld.AppendFormat("CorporationName='{0}',", string.IsNullOrEmpty(TdUser.CorporationName) ? string.Empty : TdUser.CorporationName);

                    strbld.AppendFormat("PermitRcash={0},", TdUser.PermitRcash ? 1 : 0);
                    strbld.AppendFormat("PermitCcash={0},", TdUser.PermitCcash ? 1 : 0);
                    strbld.AppendFormat("PermitDhuo={0},", TdUser.PermitDhuo ? 1 : 0);
                    strbld.AppendFormat("PermitHshou={0},", TdUser.PermitHshou ? 1 : 0);
                    strbld.AppendFormat("PermitRstore={0},", TdUser.PermitRstore ? 1 : 0);
                    strbld.AppendFormat("PermitDelOrder={0},", TdUser.PermitDelOrder ? 1 : 0);
                }
                strbld.AppendFormat("LastUpdateTime='{0}',", strdt); //修改时间
                strbld.AppendFormat("LastUpdateID='{0}'", operUser); //修改人
                strbld.AppendFormat(" where Account='{0}' and userid='{1}'", TdUser.Account, userid);
                sqlList.Add(strbld.ToString());
                //修改资金信息
                sqlList.Add(string.Format("update Trade_FundInfo set AccountName='{0}',BankCard='{1}',OpenBank='{2}',ConBankType='{4}' where userid='{3}'",
                    TdUser.UserName, Fdinfo.BankCard, Fdinfo.OpenBank, userid, Fdinfo.ConBankType));
                //com.individual.helper.LogNet4.WriteMsg(strbld.ToString());
                //添加操作记录
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)RefTdUser.UType, string.Format("{1}修改用户{0}", TdUser.Account, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "修改用户资料出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "修改用户资料成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "修改用户资料失败";
            }
            return rsdc;
        }
 /// <summary>
 /// 获取交易用户信息
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public static TradeUser GetTdUser(string sql)
 {
     System.Data.Common.DbDataReader dbreader = null;
     TradeUser tdUser = new TradeUser();
     try
     {
         dbreader = DbHelper.ExecuteReader(sql);
         while (dbreader.Read())
         {
             tdUser.UserID = System.DBNull.Value != dbreader["UserID"] ? dbreader["UserID"].ToString() : string.Empty;
             break;
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
     finally
     {
         if (null != dbreader)
         {
             dbreader.Close();
             dbreader.Dispose();
         }
     }
     return tdUser;
 }
        /// <summary>
        /// 客户资金资料修改
        /// </summary>
        /// <param name="Fdinfo">资金信息</param>
        /// <param name="tradeAccount">用户帐号</param>
        /// <param name="LoginId">登陆标识</param>
        /// <returns>修改结果</returns>
        public ResultDesc ModifyUserFundinfo(Fundinfo Fdinfo, string tradeAccount, string LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            TradeUser RefTdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期
                if (!ComFunction.ExistUserLoginID(LoginId, ref RefTdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }

                if (UserType.NormalType == RefTdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = RefTdUser.Account;
                #endregion

                //SQL语句
                List<string> sqlList = new List<string>();
                string userid = ComFunction.GetUserId(tradeAccount);
                string strdt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                //构造修改用户信息的sql语句
                StringBuilder strbld = new StringBuilder();
                strbld.AppendFormat("update Trade_FundInfo set ");

                //strbld.AppendFormat("ConBankType='{0}', ", string.IsNullOrEmpty(Fdinfo.ConBankType) ? string.Empty : Fdinfo.ConBankType);

                //strbld.AppendFormat("OpenBank='{0}', ", string.IsNullOrEmpty(Fdinfo.OpenBank) ? string.Empty : Fdinfo.OpenBank);
                //strbld.AppendFormat("BankAccount='{0}', ", string.IsNullOrEmpty(Fdinfo.BankAccount) ? string.Empty : Fdinfo.BankAccount);
                //strbld.AppendFormat("BankCard='{0}', ", string.IsNullOrEmpty(Fdinfo.BankCard) ? string.Empty : Fdinfo.BankCard);
                //strbld.AppendFormat("AccountName='{0}', ", string.IsNullOrEmpty(Fdinfo.AccountName) ? string.Empty : Fdinfo.AccountName);
                //strbld.AppendFormat("OpenBankAddress='{0}' ", string.IsNullOrEmpty(Fdinfo.OpenBankAddress) ? string.Empty : Fdinfo.OpenBankAddress);
                strbld.AppendFormat("DongJieMoney={0} ", Fdinfo.DongJieMoney);

                strbld.AppendFormat(" where userid='{0}' and [state]<>'4'", userid);
                sqlList.Add(strbld.ToString());
                //添加操作记录
                string ipmac = ComFunction.GetIpMac(RefTdUser.Ip, RefTdUser.Mac);
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)RefTdUser.UType,
                    string.Format("{2}修改{0}的冻结资金为{1}", tradeAccount, Fdinfo.DongJieMoney, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "修改用户资金资料出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "修改用户资金资料成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "修改用户资金资料失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 根据用户ID获取用户信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static TradeUser GetTradeUserByUserid(string userid)
        {
            SqlConnection sqlconn = null;
            SqlCommand sqlcmd = null;
            SqlDataReader dbreader = null;
            TradeUser TdUser = new TradeUser();

            try
            {
                sqlconn = new SqlConnection(SqlConnectionString);
                sqlconn.Open();
                sqlcmd = sqlconn.CreateCommand();

                sqlcmd.CommandText = string.Format(@"select [orgid],[Reperson],[OrgName],[telephone],[BindAccount],[userName],[UserId],[status],[Accounttype],[CorporationName],[Account],[LoginPwd],[cashPwd],
                [CardType],[CardNum],[PhoneNum],[TelNum],[Email],[LinkMan],[LinkAdress],[OrderPhone],
                [sex],[OpenMan],[OpenTime],[LastUpdateTime],[LastUpdateID],[Ip],[Mac],[LastLoginTime],[Online],
                [MinTrade],[OrderUnit],[MaxTrade],[PermitRcash],[PermitCcash],[PermitDhuo],[PermitHshou],[DongJieMoney],
                [PermitRstore],[PermitDelOrder], [BankState],[money],[OccMoney],[frozenMoney],[BankAccount],
                [AccountName],[BankCard],[SubUser],[TanUser],[ConBankType],[OpenBank],[OpenBankAddress],[UserType],[usergroupid] from [V_TradeUser] where userid='{0}'", userid);
                dbreader = sqlcmd.ExecuteReader();
                while (dbreader.Read())
                {
                    TdUser.Reperson = System.DBNull.Value != dbreader["Reperson"] ? dbreader["Reperson"].ToString() : string.Empty;
                    TdUser.BindAccount = System.DBNull.Value != dbreader["BindAccount"] ? dbreader["BindAccount"].ToString() : string.Empty;
                    TdUser.UserID = System.DBNull.Value != dbreader["UserID"] ? dbreader["UserID"].ToString() : string.Empty;
                    TdUser.UserName = System.DBNull.Value != dbreader["UserName"] ? dbreader["UserName"].ToString() : string.Empty;
                    TdUser.Status = System.DBNull.Value != dbreader["Status"] ? dbreader["Status"].ToString() : string.Empty;
                    TdUser.AccountType = System.DBNull.Value != dbreader["AccountType"] ? dbreader["AccountType"].ToString() : string.Empty;
                    TdUser.Account = System.DBNull.Value != dbreader["Account"] ? dbreader["Account"].ToString() : string.Empty;
                    TdUser.LoginPwd = System.DBNull.Value != dbreader["LoginPwd"] ? Des3.Des3DecodeCBC(dbreader["LoginPwd"].ToString()) : string.Empty;
                    TdUser.CashPwd = System.DBNull.Value != dbreader["CashPwd"] ? Des3.Des3DecodeCBC(dbreader["CashPwd"].ToString()) : string.Empty;
                    TdUser.CardType = System.DBNull.Value != dbreader["CardType"] ? dbreader["CardType"].ToString() : string.Empty;
                    TdUser.CardNum = System.DBNull.Value != dbreader["CardNum"] ? dbreader["CardNum"].ToString() : string.Empty;
                    TdUser.PhoneNum = System.DBNull.Value != dbreader["PhoneNum"] ? dbreader["PhoneNum"].ToString() : string.Empty;
                    TdUser.TelNum = System.DBNull.Value != dbreader["TelNum"] ? dbreader["TelNum"].ToString() : string.Empty;
                    TdUser.Email = System.DBNull.Value != dbreader["Email"] ? dbreader["Email"].ToString() : string.Empty;
                    TdUser.LinkMan = System.DBNull.Value != dbreader["LinkMan"] ? dbreader["LinkMan"].ToString() : string.Empty;
                    TdUser.LinkAdress = System.DBNull.Value != dbreader["LinkAdress"] ? dbreader["LinkAdress"].ToString() : string.Empty;
                    TdUser.Sex = System.DBNull.Value != dbreader["Sex"] ? dbreader["Sex"].ToString() : string.Empty;
                    TdUser.OpenMan = System.DBNull.Value != dbreader["OpenMan"] ? dbreader["OpenMan"].ToString() : string.Empty;
                    TdUser.OpenTime = System.DBNull.Value != dbreader["OpenTime"] ? Convert.ToDateTime(dbreader["OpenTime"]) : DateTime.MinValue;
                    TdUser.LastUpdateTime = System.DBNull.Value != dbreader["LastUpdateTime"] ? Convert.ToDateTime(dbreader["LastUpdateTime"]) : DateTime.MinValue;
                    TdUser.LastUpdateID = System.DBNull.Value != dbreader["LastUpdateID"] ? dbreader["LastUpdateID"].ToString() : string.Empty;

                    TdUser.Ip = System.DBNull.Value != dbreader["Ip"] ? dbreader["Ip"].ToString() : string.Empty;
                    TdUser.Mac = System.DBNull.Value != dbreader["Mac"] ? dbreader["Mac"].ToString() : string.Empty;
                    TdUser.LastLoginTime = System.DBNull.Value != dbreader["LastLoginTime"] ? Convert.ToDateTime(dbreader["LastLoginTime"]) : DateTime.MinValue;
                    TdUser.Online = System.DBNull.Value != dbreader["Online"] ? Convert.ToBoolean(dbreader["Online"]) : false;
                    TdUser.MinTrade = System.DBNull.Value != dbreader["MinTrade"] ? Convert.ToDouble(dbreader["MinTrade"]) : 0;
                    TdUser.OrderUnit = System.DBNull.Value != dbreader["OrderUnit"] ? Convert.ToDouble(dbreader["OrderUnit"]) : 0;
                    TdUser.MaxTrade = System.DBNull.Value != dbreader["MaxTrade"] ? Convert.ToDouble(dbreader["MaxTrade"]) : 0;
                    TdUser.PermitRcash = System.DBNull.Value != dbreader["PermitRcash"] ? Convert.ToBoolean(dbreader["PermitRcash"]) : false;
                    TdUser.PermitCcash = System.DBNull.Value != dbreader["PermitCcash"] ? Convert.ToBoolean(dbreader["PermitCcash"]) : false;
                    TdUser.PermitDhuo = System.DBNull.Value != dbreader["PermitDhuo"] ? Convert.ToBoolean(dbreader["PermitDhuo"]) : false;
                    TdUser.PermitHshou = System.DBNull.Value != dbreader["PermitHshou"] ? Convert.ToBoolean(dbreader["PermitHshou"]) : false;
                    TdUser.PermitRstore = System.DBNull.Value != dbreader["PermitRstore"] ? Convert.ToBoolean(dbreader["PermitRstore"]) : false;
                    TdUser.PermitDelOrder = System.DBNull.Value != dbreader["PermitDelOrder"] ? Convert.ToBoolean(dbreader["PermitDelOrder"]) : false;
                    TdUser.CorporationName = System.DBNull.Value != dbreader["CorporationName"] ? dbreader["CorporationName"].ToString() : string.Empty;
                    TdUser.OrderPhone = System.DBNull.Value != dbreader["OrderPhone"] ? dbreader["OrderPhone"].ToString() : string.Empty;

                    TdUser.BankState = System.DBNull.Value != dbreader["BankState"] ? dbreader["BankState"].ToString() : string.Empty;
                    TdUser.Money = System.DBNull.Value != dbreader["Money"] ? Convert.ToDouble(dbreader["Money"]) : 0;
                    TdUser.OccMoney = System.DBNull.Value != dbreader["OccMoney"] ? Convert.ToDouble(dbreader["OccMoney"]) : 0;
                    TdUser.FrozenMoney = System.DBNull.Value != dbreader["FrozenMoney"] ? Convert.ToDouble(dbreader["FrozenMoney"]) : 0;
                    TdUser.DongJieMoney = System.DBNull.Value != dbreader["DongJieMoney"] ? Convert.ToDouble(dbreader["DongJieMoney"]) : 0;
                    TdUser.BankAccount = System.DBNull.Value != dbreader["BankAccount"] ? dbreader["BankAccount"].ToString() : string.Empty;
                    TdUser.AccountName = System.DBNull.Value != dbreader["AccountName"] ? dbreader["AccountName"].ToString() : string.Empty;
                    TdUser.BankCard = System.DBNull.Value != dbreader["BankCard"] ? dbreader["BankCard"].ToString() : string.Empty;

                    TdUser.SubUser = System.DBNull.Value != dbreader["SubUser"] ? dbreader["SubUser"].ToString() : string.Empty;
                    TdUser.TanUser = System.DBNull.Value != dbreader["TanUser"] ? dbreader["TanUser"].ToString() : string.Empty;
                    TdUser.ConBankType = System.DBNull.Value != dbreader["ConBankType"] ? dbreader["ConBankType"].ToString() : string.Empty;
                    TdUser.OpenBank = System.DBNull.Value != dbreader["OpenBank"] ? dbreader["OpenBank"].ToString() : string.Empty;
                    TdUser.OpenBankAddress = System.DBNull.Value != dbreader["OpenBankAddress"] ? dbreader["OpenBankAddress"].ToString() : string.Empty;

                    TdUser.OrgName = System.DBNull.Value != dbreader["OrgName"] ? dbreader["OrgName"].ToString() : string.Empty;
                    TdUser.Telephone = System.DBNull.Value != dbreader["telephone"] ? dbreader["telephone"].ToString() : string.Empty;
                    TdUser.OrgId = System.DBNull.Value != dbreader["orgid"] ? dbreader["orgid"].ToString() : string.Empty;

                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (null != sqlconn)
                {
                    sqlconn.Close();
                }
                if (null != dbreader)
                {
                    dbreader.Close();
                }
            }
            return TdUser;
        }
        /// <summary>
        /// 2.3.4.4	修改客户组
        /// </summary>
        /// <param name="ugs"></param>
        /// <param name="LoginId"></param>
        /// <returns></returns>
        public ResultDesc ModifyUserGroups(UserGroups ugs, String LoginId)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;

                #endregion

                if (string.IsNullOrEmpty(ugs.UserGroupName))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "客户组名称不能为空";
                    return rsdc;
                }
                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();
                strbld.Append("update Trade_UserGroups set ");
                strbld.AppendFormat(" UserGroupName='{0}',", string.IsNullOrEmpty(ugs.UserGroupName) ? string.Empty : ugs.UserGroupName);
                strbld.AppendFormat(" IsDefaultGroup={0},", ugs.IsDefaultGroup);
                strbld.AppendFormat(" AfterSecond={0},", ugs.AfterSecond);
                strbld.AppendFormat(" PlaceOrderSlipPoint={0},", ugs.PlaceOrderSlipPoint);
                strbld.AppendFormat(" FlatOrderSlipPoint={0},", ugs.FlatOrderSlipPoint);
                strbld.AppendFormat(" DelayPlaceOrder={0},", ugs.DelayPlaceOrder);
                strbld.AppendFormat(" DelayFlatOrder={0} ", ugs.DelayFlatOrder);
                strbld.AppendFormat(" where UserGroupId='{0}'", ugs.UserGroupId);
                sqlList.Add(strbld.ToString());
                if (1 == ugs.IsDefaultGroup)//如果修改的组被设置为默认组时,需要把其他组全部修改为非默认组
                {
                    sqlList.Add(string.Format("update Trade_UserGroups set IsDefaultGroup=0 where UserGroupId<>'{0}'", ugs.UserGroupId));
                }
                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "修改客户组出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "修改客户组成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "修改客户组失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 签约华夏银行 他行开户
        /// </summary>
        /// <param name="TdUser">用户信息</param>
        /// <param name="openbank">开户行信息</param>
        /// <param name="codeDesc">签约结果代码描述</param>
        /// <param name="subUser">子账号</param>
        /// <returns>成功返回true 失败返回fasle</returns>
        public static bool ContactToHuaxiaOhterBank(TradeUser TdUser, OpenBankInfo openbank, ref string codeDesc, ref string subUser)
        {
            bool IsSuc = false;
            IntersServerImplClient ic = new IntersServerImplClient();
            try
            {
                StringBuilder inXml = new StringBuilder();
                inXml.Append("<HXBB2B>");
                inXml.Append("<MessageData>");

                inXml.Append("<Base>");
                inXml.Append("<Version>1.0</Version>");
                inXml.Append("<SignFlag>0</SignFlag>");
                inXml.Append("<Language>GB2312</Language>");
                inXml.Append("</Base>");

                inXml.Append("<ReqHeader>");
                inXml.AppendFormat("<ClientTime>{0}</ClientTime>", DateTime.Now.ToString("yyyyMMddHHmmss"));
                inXml.Append("<MerchantNo>600014</MerchantNo>");
                inXml.Append("</ReqHeader>");

                inXml.Append("<DataBody>");
                inXml.AppendFormat("<MerTxSerNo>{0}</MerTxSerNo>", TdUser.CashUser);
                inXml.Append("<TrnxCode>DZ020</TrnxCode>");
                inXml.Append("<AccountInfos>");
                inXml.Append("<AccountInfo>");

                inXml.AppendFormat("<MerAccountNo>{0}</MerAccountNo>", GetTanUser(TdUser.TanUser));
                inXml.AppendFormat("<AccountName>{0}</AccountName>", TdUser.UserName);
                inXml.AppendFormat("<AccountProp>{0}</AccountProp>", "0" == TdUser.AccountType ? 1 : 0);//华夏银行接口中,0表示企业1表示个人
                inXml.AppendFormat("<RelatingAcct>{0}</RelatingAcct>", openbank.BankCard);
                inXml.AppendFormat("<RelatingAcctName>{0}</RelatingAcctName>", openbank.AccountName);
                inXml.Append("<InterBankFlag>1</InterBankFlag>");
                inXml.AppendFormat("<RelatingAcctBank>{0}</RelatingAcctBank>", openbank.OpenBank);
                inXml.AppendFormat("<RelatingAcctBankAddr>{0}</RelatingAcctBankAddr>", openbank.OpenBankAddress);
                inXml.AppendFormat("<RelatingAcctBankCode>{0}</RelatingAcctBankCode>", openbank.BankAccount);
                inXml.Append("<Amt></Amt>");
                inXml.Append("<AmtUse></AmtUse>");
                inXml.AppendFormat("<PersonName>{0}</PersonName>", string.IsNullOrEmpty(TdUser.LinkMan) ? string.Empty : TdUser.LinkMan);
                inXml.AppendFormat("<OfficeTel>{0}</OfficeTel>", string.IsNullOrEmpty(TdUser.TelNum) ? string.Empty : TdUser.TelNum);
                inXml.AppendFormat("<MobileTel>{0}</MobileTel>", string.IsNullOrEmpty(TdUser.PhoneNum) ? string.Empty : TdUser.PhoneNum);
                inXml.AppendFormat("<Addr>{0}</Addr>", string.IsNullOrEmpty(TdUser.LinkAdress) ? string.Empty : TdUser.LinkAdress);
                inXml.Append("<ZipCode></ZipCode>");
                inXml.AppendFormat("<LawName>{0}</LawName>", string.IsNullOrEmpty(TdUser.CorporationName) ? string.Empty : TdUser.CorporationName);
                inXml.AppendFormat("<LawType>{0}</LawType>", "1" == TdUser.CardType ? 1 : 6);
                //华夏证件类型:
                //1 – 个人身份证
                //2 – 军人证、警官证
                //3 – 临时证件
                //4 – 户口本
                //5 – 护照
                //6 – 其他

                inXml.AppendFormat("<LawNo>{0}</LawNo>", string.IsNullOrEmpty(TdUser.CardNum) ? string.Empty : TdUser.CardNum);
                inXml.Append("<NoteFlag>1</NoteFlag>");
                inXml.AppendFormat("<NotePhone>{0}</NotePhone>", string.IsNullOrEmpty(TdUser.PhoneNum) ? string.Empty : TdUser.PhoneNum);
                inXml.AppendFormat("<EMail>{0}</EMail>", string.IsNullOrEmpty(TdUser.Email) ? string.Empty : TdUser.Email);
                inXml.AppendFormat("<CheckFlag>{0}</CheckFlag>", "1" == TdUser.AccountType ? 1 : 0);

                inXml.Append("</AccountInfo>");
                inXml.Append("</AccountInfos>");
                inXml.Append("</DataBody>");

                inXml.Append("</MessageData>");
                inXml.Append("</HXBB2B>");
                com.individual.helper.LogNet4.WriteMsg("华夏银行他行签约,请求的Xml报文:" + inXml.ToString());
                string outXml = ic.Process(inXml.ToString());
                com.individual.helper.LogNet4.WriteMsg("华夏银行他行签约,响应的Xml报文:" + outXml);
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(outXml);
                if (HuaxiaSuc == xmldoc.SelectSingleNode("HXBB2B/MessageData/ResHeader/Status/Code").InnerText)
                {
                    subUser = xmldoc.SelectSingleNode("HXBB2B/MessageData/DataBody/AccountInfos/AccountInfo/AccountNo").InnerText;
                    IsSuc = true;
                }
                codeDesc = xmldoc.SelectSingleNode("HXBB2B/MessageData/ResHeader/Status/Message").InnerText;
                ic.Close();
            }
            catch (Exception ex)
            {
                ic.Abort();
                throw new Exception(ex.Message, ex);
            }

            return IsSuc;
        }
        /// <summary>
        /// 手工调账或库存结算
        /// </summary>
        /// <param name="LoginId">登陆标识</param>
        /// <param name="TradeAccount">用户交易账号</param>
        /// <param name="money">调整资金</param>
        /// <param name="ReasonType">原因(3-库存结算,6-手工调账)</param>
        /// <returns>调整结果</returns>
        public ResultDesc ModifyUserMoney(string LoginId, string TradeAccount, double money, int ReasonType)
        {
            //ReasonType字段说明:(该接口取3,6)
            //0----入金(组织或管理员操作);
            //1----出金(组织或管理员操作);
            //2----订单操作
            //3----库存结算(组织或管理员操作);
            //4----银行入金 (用户操作);
            //5----银行出金 (用户操作)
            //6----手工调账(组织或管理员操作)
            //7----在线回购(用户操作);
            //8----其他费用;

            ResultDesc rsdc = new ResultDesc();
            string userid = string.Empty; //用户ID
            string operUser = string.Empty; //操作人

            TradeUser TdUser = new TradeUser();
            try
            {
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion

                userid = ComFunction.GetUserId(TradeAccount);

                //获取现有资金信息
                Fundinfo Fdinfo = ComFunction.GetFdinfo(string.Format("select * from Trade_FundInfo where userid='{0}' and state<>'4'", userid));

                if (Fdinfo.Money + money < 0)
                {
                    rsdc.Result = false;
                    rsdc.Desc = string.Format("{0}失败!因为用户{1}现有余额为{2},调整金额为{3},调整后的金额小于0", 3 == ReasonType ? "库存结算" : "手工调账", TradeAccount, Fdinfo.Money, money);
                    return rsdc;
                }

                #region 数据库事务处理

                //SQL语句
                List<string> sqlList = new List<string>();

                //添加调整资金sql语句
                sqlList.Add(string.Format("update Trade_FundInfo set money=money+{0} where userid='{1}' and state<>'4'", money, userid));

                //添加资金变动记录sql语句
                sqlList.Add(string.Format("insert into Fund_Change([userId],[reason],[Oldvalue],[NewValue],[OperUser],[OperTime],[RelaOrder],[ChangeValue],[CashUser]) values('{0}','{1}',{2},{3},'{4}','{5}','{6}',{7},'{8}')", userid, ReasonType, Fdinfo.Money, Fdinfo.Money + money, operUser, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), string.Empty, money, Fdinfo.CashUser));

                string operrationDesc = string.Empty;
                if (3 == ReasonType)
                {
                    operrationDesc = string.Format("对用户{0},库存结算{1}", TradeAccount, money);
                }
                else if (6 == ReasonType)
                {
                    operrationDesc = string.Format("对用户{0},手工调帐{1}", TradeAccount, money);
                }
                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                //添加操作记录
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, ipmac + operrationDesc));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    rsdc.Result = false;
                    rsdc.Desc = "调整资金出错";
                    return rsdc;
                }
                rsdc.Result = true;
                rsdc.Desc = "调整资金成功";
                #endregion
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "调整资金失败";
            }
            return rsdc;
        }
        /// <summary>
        /// 根据登陆ID判断用户登陆登陆用户是否存在
        /// </summary>
        /// <param name="LoginID">登陆标识</param>
        /// <param name="TdUser">用户信息</param>
        /// <returns>返回结果为true or false</returns>
        public static bool ExistUserLoginID(string LoginID, ref TradeUser TdUser)
        {
            bool exist = false;
            System.Data.Common.DbDataReader dbreader = null;
            try
            {
                string strSql = "select ip,mac,OrgId,UserType, Account, MinTrade,OrderUnit,MaxTrade,PermitRcash,PermitCcash,PermitDhuo,PermitHshou,PermitRstore,PermitDelOrder,userId,CashPwd,LoginPwd from Base_User where LoginID=@LoginID";

                dbreader = DbHelper.ExecuteReader(strSql,
                    new System.Data.Common.DbParameter[] { DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type, "@LoginID", DbParameterType.String, LoginID, ParameterDirection.Input) });
                if (dbreader.Read())
                {
                    TdUser.OrgId = System.DBNull.Value != dbreader["OrgId"] ? dbreader["OrgId"].ToString() : string.Empty;
                    TdUser.UType = System.DBNull.Value != dbreader["UserType"] ? (UserType)(dbreader["UserType"]) : UserType.AdminType;
                    TdUser.Account = System.DBNull.Value != dbreader["Account"] ? dbreader["Account"].ToString() : string.Empty;
                    TdUser.MinTrade = System.DBNull.Value != dbreader["MinTrade"] ? Convert.ToDouble(dbreader["MinTrade"]) : 1;
                    TdUser.OrderUnit = System.DBNull.Value != dbreader["OrderUnit"] ? Convert.ToDouble(dbreader["OrderUnit"]) : 0.5;//默认为0.5
                    TdUser.MaxTrade = System.DBNull.Value != dbreader["MaxTrade"] ? Convert.ToDouble(dbreader["MaxTrade"]) : 50;
                    TdUser.PermitRcash = System.DBNull.Value != dbreader["PermitRcash"] ? Convert.ToBoolean(dbreader["PermitRcash"]) : false;
                    TdUser.PermitCcash = System.DBNull.Value != dbreader["PermitCcash"] ? Convert.ToBoolean(dbreader["PermitCcash"]) : false;
                    TdUser.PermitDhuo = System.DBNull.Value != dbreader["PermitDhuo"] ? Convert.ToBoolean(dbreader["PermitDhuo"]) : false;
                    TdUser.PermitHshou = System.DBNull.Value != dbreader["PermitHshou"] ? Convert.ToBoolean(dbreader["PermitHshou"]) : false;
                    TdUser.PermitRstore = System.DBNull.Value != dbreader["PermitRstore"] ? Convert.ToBoolean(dbreader["PermitRstore"]) : false;
                    TdUser.PermitDelOrder = System.DBNull.Value != dbreader["PermitDelOrder"] ? Convert.ToBoolean(dbreader["PermitDelOrder"]) : false;
                    TdUser.LoginPwd = System.DBNull.Value != dbreader["LoginPwd"] ? dbreader["LoginPwd"].ToString() : string.Empty;
                    TdUser.CashPwd = System.DBNull.Value != dbreader["CashPwd"] ? dbreader["CashPwd"].ToString() : string.Empty;
                    TdUser.UserID = System.DBNull.Value != dbreader["userId"] ? dbreader["userId"].ToString() : string.Empty;
                    TdUser.Ip = System.DBNull.Value != dbreader["ip"] ? dbreader["ip"].ToString() : string.Empty;
                    TdUser.Mac = System.DBNull.Value != dbreader["mac"] ? dbreader["mac"].ToString() : string.Empty;
                    exist = true;
                }
                else
                {
                    exist = false;
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (null != dbreader)
                {
                    dbreader.Close();
                    dbreader.Dispose();
                }
            }
            return exist;
        }
        /// <summary>
        /// 出金付款处理
        /// </summary>
        /// <param name="ApplyId"></param>
        /// <param name="LoginId"></param>
        /// <param name="state">处理状态,"1"-已付款,"2"已拒绝 "3"处理中 "4"处理失败</param>
        /// <returns></returns>
        public ResultDesc ProcessChuJin(int ApplyId, String LoginId,ref string state)
        {
            ResultDesc rsdc = new ResultDesc();
            string operUser = string.Empty;//操作人
            try
            {
                TradeUser TdUser = new TradeUser();
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(LoginId, ref TdUser))
                {
                    rsdc.Result = false;
                    rsdc.Desc = ResCode.UL003Desc;
                    return rsdc;
                }
                if (UserType.NormalType == TdUser.UType)
                {
                    rsdc.Result = false;
                    rsdc.Desc = ComFunction.NotRightUser;
                    return rsdc;
                }
                operUser = TdUser.Account;
                #endregion
                List<string> sqlList = new List<string>();
                StringBuilder strbld = new StringBuilder();

                #region 暂时作废
                //string ret_cod = string.Empty;
                //string ret_msg = string.Empty;
                //string ret_cod2 = string.Empty;//中间状态2000 2001 2003 2005 2007 2008
                //string ret_msg2 = string.Empty;
                //int itmp = 0;//临时变量
                //#region 调银行接口
                //ComFunction.ProcessChuJin(ApplyId, ref ret_cod, ref ret_msg, ref ret_cod2, ref ret_msg2);
                //#endregion

                //strbld.AppendFormat("update Trade_ChuJin set ");
                //if ("0000" == ret_cod && "0000" == ret_cod2)
                //{
                //    strbld.AppendFormat(" State=1, FkTime='{0}' ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                //    strbld.AppendFormat(" where ApplyId={0}", ApplyId);
                //    sqlList.Add(strbld.ToString());
                //}
                //else if ("2000" == ret_cod2 || "2001" == ret_cod2 || "2003" == ret_cod2 || "2005" == ret_cod2 || "2007" == ret_cod2 || "2008" == ret_cod2)
                //{
                //    strbld.AppendFormat(" FkTime='{0}',", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                //    strbld.AppendFormat(" State=3 where ApplyId={0}", ApplyId);//状态改为正在处理
                //    sqlList.Add(strbld.ToString());
                //    itmp = 1;
                //}
                ////失败代码0001 0002 1000 1001 1002 1999 2002 2004 2006
                //else if ("0001" == ret_cod2 || "0002" == ret_cod2 || "1000" == ret_cod2 || "1001" == ret_cod2 || "1002" == ret_cod2
                //    || "1999" == ret_cod2 || "2002" == ret_cod2 || "2004" == ret_cod2 || "2006" == ret_cod2)
                //{
                //    strbld.AppendFormat(" State=4, FkTime='{0}' ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                //    strbld.AppendFormat(" where ApplyId={0}", ApplyId);
                //    sqlList.Add(strbld.ToString());
                //    itmp = 2;
                //}
                //else
                //{
                //    rsdc.Result = false;
                //    rsdc.Desc = "付款失败!";
                //    return rsdc;
                //}
                #endregion

                #region 改为微信支付后,付款功能直接修改状态为处理中
                strbld.AppendFormat("update Trade_ChuJin set ");
                //strbld.AppendFormat(" FkTime='{0}',", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                if (ConfigurationManager.AppSettings["VersionFlag"] == "HFB")
                {
                    strbld.AppendFormat(" State=1 where ApplyId={0}", ApplyId); //状态改为已付款(黑琥珀)
                    state = "1";
                }

                else
                {
                    strbld.AppendFormat(" State=3 where ApplyId={0}", ApplyId);//状态改为正在处理
                    state = "3";
                }

                sqlList.Add(strbld.ToString());
                #endregion

                string ipmac = ComFunction.GetIpMac(TdUser.Ip, TdUser.Mac);
                sqlList.Add(string.Format("insert into Base_OperrationLog([OperTime],[Account],[UserType],[Remark]) values('{0}','{1}',{2},'{3}')",
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), operUser, (int)TdUser.UType, string.Format("{1}出金处理:ApplyId={0}", ApplyId, ipmac)));

                if (!ComFunction.SqlTransaction(sqlList))
                {
                    com.individual.helper.LogNet4.WriteMsg("付款已处理,但数据库sql执行失败了!");
                    state = "4";
                }
                rsdc.Result = true;
                rsdc.Desc = "处理中";
                //if (1 == itmp)
                //{
                //    rsdc.Desc = "3";//表示正在处理
                //}
                //else if (2 == itmp)
                //{
                //    rsdc.Desc = "4";//表示交易处理失败
                //}
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                rsdc.Result = false;
                rsdc.Desc = "付款失败!";
                state = "4";
            }
            return rsdc;
        }