0

希望有人可以帮助我。我有一个方法(user_login),而不是提示用户登录,然后生成并返回发票和令牌。

问题是如果用户已经登录(我将它保存在列表中),则不能调用方法 svr.logonex。我应该从前一个实例中检索值。我想我必须保存 svr 变量,但我不知道该怎么做。任何帮助将不胜感激。谢谢

这是代码:

public EPS30Ora.LogonResult User_Login(input_params inputparams)
        {
          EPS30Ora.EPS30Svr svr = new EPS30Ora.EPS30Svr();
         if (Users.Exists(Username => Username.Username.Equals(inputparams.Username)))
            {
                List<input_params> selected = Users.Where(Username => Username.Username.Equals(inputparams.Username)).ToList();
                svr.PrepareByMoney(selected[0].ck, 1, inputparams.meter_number, 10, 0, ref cal);
            }
            else 
            {

                Log_Res = svr.LogOnEx("EDEESTE", inputparams.VSID, inputparams.Username, inputparams.Password, "EPS30Ora", ref inputparams.ck);

                if (Log_Res == EPS30Ora.LogonResult.psOK)
                {
                    try
                    {
                        Users.Add(inputparams);
                        object tr_bl = svr.GetInvoiceData(inputparams.ck, svr.Confirm(inputparams.ck));
                    }
                    catch (System.Runtime.InteropServices.COMException ex)
                    {
                        Trace.WriteLine("Se ha producido una excepción: " + ex);

                    }
              }


            }

            return Log_Res;
        }
4

2 回答 2

1

听起来你需要拉这个:

EPS30Ora.EPS30Svr svr = 新 EPS30Ora.EPS30Svr();

退出 Login 方法,并将其移动到调用此方法的任何对象中,以使该对象在范围内保持更长的时间。否则,当您从该方法返回时,该对象将被销毁。

然后,您可以将其作为参数传递给此方法,例如:

// Start user process

EPS30Ora.EPS30Svr svr = new EPS30Ora.EPS30Svr();

if (Users.Exists(Username => Username.Username.Equals(inputparams.Username))) {
 // do something
}
else {

}

...

public LogOn(EPS30Ora.EPS30Svr svr, input_params inputparams)
{
Log_Res = svr.LogOnEx("EDEESTE", inputparams.VSID, inputparams.Username, inputparams.Password, "EPS30Ora", ref inputparams.ck);
}
于 2013-05-21T21:01:10.783 回答
0
namespace EPSInvoice_ServiceLibrary
{

    public class EPS_Service : IEPS_Service
    {
        List<input_params> Users = new List<input_params>();
        List<token_data> token_data = new List<token_data>();
        public decimal cal;


        public EPS30Ora.LogonResult Invoice(input_params inputparams)
        {
            EPS30Ora.EPS30Svr svr = new EPS30Ora.EPS30Svr();
            EPS30Ora.LogonResult Log_Res = new EPS30Ora.LogonResult();
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Trace.AutoFlush = true;
            Trace.Indent();

            if (Users.Exists(Username => Username.Username.Equals(inputparams.Username)))
            {
                List<input_params> selected = Users.Where(Username => Username.Username.Equals(inputparams.Username)).ToList();
                Trace.WriteLine("Username: " + inputparams.Username + " ya está logeado " + selected[0].ck);
                //    svr.PrepareByMoney(selected[0].ck, 1, inputparams.meter_number, 10, 0, ref cal);
            }
            else
            {

                try
                {
                    Log_Res = svr.LogOnEx("EDEESTE", inputparams.VSID, inputparams.Username, inputparams.Password, "EPS30Ora", ref inputparams.ck);
                    if (Log_Res == EPS30Ora.LogonResult.psOK)
                    {
                        Users.Add(inputparams);
                        Trace.WriteLine("Login OK. Username: " + inputparams.Username);
                        svr.PrepareByMoney(inputparams.ck, 1, inputparams.meter_number, 10, 0, ref cal);
                        object tr_bl = svr.GetInvoiceData(inputparams.ck, svr.Confirm(inputparams.ck));
                        token_data.Add(new token_data() { transfer_number = (string)((object[])(((object[])(((object[])(((object[])(tr_bl))[4]))[1]))[0]))[0] });
                        Trace.WriteLine("Transacción Finalizada. NTC obtenido: " + inputparams.ck);
                        Trace.Unindent();
                    }
                }

                catch (System.Runtime.InteropServices.COMException ex)
                {
                    Trace.WriteLine("Se ha producido una excepción: " + ex);
                }
            }
         return Log_Res;
        }




    }



}
于 2013-05-22T13:14:48.307 回答