コード例 #1
0
ファイル: CommonDAL.cs プロジェクト: sky-tc/U8
        /// <summary>

        /// 时间:2010-09-01
        /// </summary>
        /// <param name="userCode">用户编码</param>
        /// <param name="password">密码</param>
        /// <param name="accid">帐套号</param>
        /// <param name="year">帐套年度</param>
        /// <param name="msgID"></param>
        /// <param name="loginTime">登入时间</param>
        /// <param name="inf"></param>
        /// <param name="loginString">登入字符串</param>
        /// <param name="dBString">数据库字符串</param>
        /// <param name="taskId">任务ID</param>
        /// <param name="errMsg">错误信息</param>
        /// <param name="loginUser">登入人</param>
        /// <param name="netLogin"></param>
        /// <param name="systemDate">系统时间</param>
        /// <param name="isTaskExc">上下岗时间权限</param>
        /// <param name="isPFReport">工序流转卡权限</param>
        /// <returns></returns>
        public static int RFLogin(string userCode, string password, string accid, string year, string msgID, DateTime loginTime, Info inf,
                                  out string loginString, out string dBString, out string taskId, out string errMsg,
                                  out string loginUser, ref UFSoft.U8.Framework.Login.UI.clsLogin netLogin
                                  , out DateTime systemDate, out bool isTaskExc, out bool isPFReport)
        {
            loginString = "";
            taskId      = "";
            loginUser   = "";
            dBString    = "";
            errMsg      = "";
            isTaskExc   = false;     //记录当前登录人员是否有修改上下岗时间的权限

            isPFReport = false;      //记录当前登录人员是否有工序流转卡完工单权限

            string ERPService  = ""; //ERP服务器地址
            string DBService   = "";
            bool   result      = false;
            string sqlUser     = "";
            string sqlPassword = "";

            systemDate = loginTime;

            string serID = msgID + "@0";     //创建加密序列号


            //string serID = "{" + Guid.NewGuid() + "}" + msgID + "@0";


            string pDate = loginTime.ToString("yyyy-MM-dd");

            try
            {
                ERPService = inf.ERPService;
                DBService  = inf.DBService;
            }
            catch (Exception ex)
            {
                errMsg = "配置文件错误" + ex.Message;
                return(-1);
            }
            U8Login.clsLoginClass login;    //创建登录对象
            netLogin = new UFSoft.U8.Framework.Login.UI.clsLogin();


            try
            {
                result = netLogin.login("DP", userCode, password, inf.ERPService, pDate, accid, serID, false); //先登录平台

                if (result)
                {
                    netLogin.WorkStationName = userCode + ":" + msgID;//ADD BY HQ 设置工作站名称

                    //netLogin.SubLogin("CJ");                              //加密服务登录用户站点 + 1

                    UFSoft.U8.Framework.LoginContext.ProductContext pcT = new UFSoft.U8.Framework.LoginContext.ProductContext();
                    pcT = netLogin.SubLogin(inf.subID);                        //加密服务登录用户站点 + 1

                    if (pcT == null)
                    {
                        errMsg = "【" + _productName + "】登录错误:" + netLogin.ErrDescript;
                        return(1);
                    }
                    taskId = netLogin.GetTaskID(inf.BarSubID);              //获得任务号
                }
                else
                {
                    errMsg = "【" + _productName + "】登录错误:" + netLogin.ErrDescript;
                    return(1);
                }

                login = new U8Login.clsLoginClass();                    //生成登录对象

                result = login.ConstructLogin(netLogin.userToken);
                result = login.Login(ref inf.BarSubID, ref accid, ref year, ref userCode, ref password, ref pDate, ref inf.ERPService, ref serID);
                if (result)
                {
                    object bDemo = false;

                    //bDemo = true; //正式版
                    //bDemo = False;    演示版


                    login.GetAccInfo(10000, ref bDemo);//判断产品是否演示版


                    isTaskExc  = true; //= login.TaskExec("FZ102013", 1, 1);             //获得上下岗时间修改权限 by zhaobo
                    isPFReport = true; // = login.TaskExec("FC06006N", 1, 1);             //获得工序流转卡权限  By zhaobo


                    if (taskId == "")
                    {
                        errMsg = "";
                    }
                    //不是演示版


                    loginUser   = login.cUserName.ToString();
                    loginString = netLogin.userToken.ToString();


                    string dataSource, catalog;
                    SplitUserID(login.UfDbName, out sqlUser, out sqlPassword, out dataSource, out catalog);//解析返回数据串


                    char[] a = new char[1];
                    a[0]        = '\"';
                    sqlUser     = sqlUser.Trim(a);
                    sqlPassword = sqlPassword.Trim(a);
                    dataSource  = dataSource.Trim(a);
                    catalog     = catalog.Trim(a);


                    dBString = "user id=" + sqlUser + ";password="******";data source=" + dataSource
                               + ";persist security info=True;initial catalog=" + catalog;

                    string tempdBstring = "user id=" + sqlUser + ";password="******";data source=" + dataSource
                                          + ";persist security info=True;initial catalog=UFSystem";
                    dBString = dBString + "|" + login.UfDbName;

                    IniU8Message(tempdBstring);

                    if (!Convert.ToBoolean(bDemo))
                    {
                        if (isDemoOver(dBString))
                        {
                            errMsg = "请购买用友U8【" + _productName + "】";
                            return(5);
                        }
                    }


                    return(0);
                }
                else
                {
                    errMsg = "错误:" + login.ShareString;
                    //
                    return(2);
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return(-2);
            }

            // return 0;
        }
コード例 #2
0
ファイル: APIOp.cs プロジェクト: sky-tc/U8
        /// <summary>
        /// 获取 vb login 和 .net login
        /// 可绕过login验证
        /// </summary>
        /// <param name="bd"></param>
        /// <param name="oSysLogin"></param>
        /// <param name="u8Login"></param>
        /// <returns></returns>
        private Model.DealResult GetU8LoginNew(Model.APIData bd, UFSoft.U8.Framework.Login.UI.clsLogin oSysLogin, U8Login.clsLogin u8Login)
        {
            Model.DealResult dr = new Model.DealResult();

            System.Diagnostics.Trace.WriteLine("  before  GetU8Login 判断格式 ");
            #region 判断格式  登录
            string strErr = ",请在[账套档案注册]模块中更新!";
            if (string.IsNullOrEmpty(bd.ConnectInfo.UserId))
            {
                dr.ResultMsg = "默认操作员不能为空" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }
            if (string.IsNullOrEmpty(bd.ConnectInfo.Source))
            {
                dr.ResultMsg = "数据源不能为空" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }
            if (string.IsNullOrEmpty(bd.ConnectInfo.AccId))
            {
                dr.ResultMsg = "账套号不能为空" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }
            if (string.IsNullOrEmpty(bd.ConnectInfo.Srv))
            {
                dr.ResultMsg = "服务器地址不能为空" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }
            if (string.IsNullOrEmpty(bd.ConnectInfo.YearId))
            {
                dr.ResultMsg = "登陆年度不能为空" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }
            else
            {
                try { int.Parse(bd.ConnectInfo.YearId); }
                catch
                {
                    dr.ResultMsg = "登陆年度格式错误:" + bd.ConnectInfo.YearId + strErr;
                    dr.ResultNum = -1;
                    Marshal.FinalReleaseComObject(u8Login);
                    throw new Exception(dr.ResultMsg);
                }
            }
            DbHelperSQLP dsp    = new DbHelperSQLP(bd.ConnectInfo.Constring);
            string       strSql = "SELECT 1 FROM UFSystem.dbo.UA_AccountDatabase A JOIN UFSystem.dbo.UA_Account B ON A.cAcc_Id=B.cAcc_Id WHERE A.cAcc_Id='" + bd.ConnectInfo.AccId + "' ";
            if (!dsp.Exists(strSql))
            {
                dr.ResultMsg = "登陆失败,原因:账套 " + bd.ConnectInfo.AccId + " 在 " + bd.ConnectInfo.Srv + " 上不存在";
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }
            #endregion

            System.Diagnostics.Trace.WriteLine("  after  GetU8Login 判断格式 ");


            bool   bLogined;
            string beginDate;

            oSysLogin = new UFSoft.U8.Framework.Login.UI.clsLogin();

            beginDate            = "";      //GetMonthBegindate(acc_ID, iYear, "12")  //用12期间构造login,12期间必有
            oSysLogin.LanguageID = "zh-CN"; // GetAccountLoginLocaleID(modUtility.GetDbName(acc_ID, iYear))

            string subId    = U8.Interface.Bus.SysInfo.subId;
            string userId   = bd.ConnectInfo.UserId;
            string accId    = bd.ConnectInfo.Source + "@" + bd.ConnectInfo.AccId;
            string yearId   = bd.ConnectInfo.YearId;
            string password = bd.ConnectInfo.Password;
            string date     = bd.ConnectInfo.Date;
            string srv      = bd.ConnectInfo.sSrv;
            string serial   = bd.ConnectInfo.Serial;

            bLogined = oSysLogin.login(subId, userId, password, srv, date, accId, serial);

            if (!bLogined)
            {
                strErr = oSysLogin.ErrDescript; //& g_fmtr.GetString("String.U8.AA.Admin.4671", g_args)
                //'strErr = oSysLogin.ErrDescript & "内置用户密码不正确!"
                //'Call WriteTransferLog(g_ologin.cAcc_ID, g_ologin.cAccName, g_ologin.cIyear, "", "准备年结环境时出现错误,错误描述:" & oSyslogin.ErrDescript & "内置用户密码不正确!")
                dr.ResultMsg = "登陆失败,原因:" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }

            UFSoft.U8.Framework.LoginContext.ProductContext oLoginContext;
            oLoginContext = new UFSoft.U8.Framework.LoginContext.ProductContext();
            oLoginContext = oSysLogin.SubLogin(U8.Interface.Bus.SysInfo.subId);

            if (null == oLoginContext)
            {
                strErr = oSysLogin.ErrDescript;
                //'MsgBox oSyslogin.ErrDescript
                //'Call WriteTransferLog(g_ologin.cAcc_ID, g_ologin.cAccName, g_ologin.cIyear, "", "准备年结环境时出现错误,错误描述:" & oSyslogin.ErrDescript)
                dr.ResultMsg = "登陆失败,原因:" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }

            //u8Login = new U8Login.clsLogin();

            if (!u8Login.ConstructLogin(oSysLogin.userToken))
            {
                strErr = u8Login.ShareString;
                //'Call WriteTransferLog(g_ologin.cAcc_ID, g_ologin.cAccName, g_ologin.cIyear, "", "准备年结环境时出现错误,错误描述:" & oLogin.ShareString)
                dr.ResultMsg = "登陆失败,原因:" + strErr;
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }

            if (!u8Login.Login(ref subId, ref accId, ref yearId, ref userId, ref password, ref date, ref srv, ref serial))
            {
                System.Diagnostics.Trace.WriteLine("    GetU8Login  failed  ");
                dr.ResultMsg = "登陆失败,原因:" + u8Login.ShareString;
                if (u8Login.ShareString.IndexOf("年度") > 0 || u8Login.ShareString.IndexOf("日期") > 0)
                {
                    dr.ResultMsg += " - " + date;
                }
                dr.ResultNum = -1;
                Marshal.FinalReleaseComObject(u8Login);
                throw new Exception(dr.ResultMsg);
            }


            return(dr);
        }