Пример #1
0
        public static Boolean Update(Student s)
        {
            Boolean results = true;

            String     commareaStr = String.Empty;
            Boolean    result      = false;
            EciRequest eciReq;

            using (GatewayConnection gwyConnection = new GatewayConnection(gwyHostName, gwyPort))
            {
                //Prepare the EciRequest
                eciReq            = new EciRequest();
                eciReq.ServerName = StudentDB.cicsServer;
                eciReq.Program    = ProgramName;
                eciReq.ExtendMode = EciExtendMode.EciNoExtend;

                String commareaString = String.Format("{0}  {1}", "M", s.ToString());
                commareaString = commareaString.PadRight(CommareaLength);

                //eciReq.SetCommareaData(new byte[CommareaLength]);
                eciReq.SetCommareaData(ASCIIEncoding.ASCII.GetBytes(commareaString));
                eciReq.UserId   = "CICSUSER";
                eciReq.Password = "";
                Console.WriteLine("ASCII: {0}", commareaStr);
                //Flow the request
                if (FlowRequest(gwyConnection, eciReq))
                {
                    byte[] commarea = eciReq.GetCommareaData();
                    commareaStr = Encoding.ASCII.GetString(commarea);
                    result      = true;
                    Console.WriteLine("Message: {0}", commareaStr.Substring(commareaStr.Length - 40, 40));
                }
            }
            return(results);
        }
Пример #2
0
        public static Student[] List(Student s)
        {
            Boolean results = true;

            String     commareaStr = String.Empty;
            Boolean    result      = false;
            EciRequest eciReq;

            byte[]         commarea = null;
            Student[]      students = null;
            List <Student> list     = null;

            using (GatewayConnection gwyConnection = new GatewayConnection(gwyHostName, gwyPort))
            {
                //Prepare the EciRequest
                eciReq            = new EciRequest();
                eciReq.ServerName = StudentDB.cicsServer;
                eciReq.Program    = ProgramName;
                eciReq.ExtendMode = EciExtendMode.EciNoExtend;

                String commareaString = String.Format("{0}  {1}", "L", s.ToString());
                commareaString = commareaString.PadRight(CommareaLength);
                Console.WriteLine("ASCII: {0}", commareaStr);
                //eciReq.SetCommareaData(new byte[CommareaLength]);
                eciReq.SetCommareaData(ASCIIEncoding.ASCII.GetBytes(commareaString));
                eciReq.UserId   = "CICSUSER";
                eciReq.Password = "";

                //Flow the request
                if (FlowRequest(gwyConnection, eciReq))
                {
                    commarea = eciReq.GetCommareaData();
                    for (int i = 3; i < commarea.Length; i++)
                    {
                        if (commarea[i] == 0)
                        {
                            commarea[i] = 32;
                        }
                    }
                    commareaStr = Encoding.ASCII.GetString(commarea);
                    setResponse(commareaStr);
                    result = true;
                    Console.WriteLine("ASCII: {0}", commareaStr);
                    Console.WriteLine("Message: {0}", commareaStr.Substring(commareaStr.Length - 40, 40));
                }

                list = new List <Student>();
                int count = (int)commarea[2];
                for (int i = 0; i < count; i++)
                {
                    list.Add(new Student(commareaStr.Substring(3 + (115 * i), 115)));
                }
            }

            if (list.Count > 0)
            {
                students = list.ToArray <Student>();
            }

            return(students);
        }
Пример #3
0
        public static Student Inquire(String STUD_ID)
        {
            EciRequest eciReq;

            //Open the Gateway connection with an infinite timeout period
            //The 'using' C# construct ensures the GatewayConnection is closed
            //when it goes out of scope, even if an exception is thrown

            //A System.Net.SocketException will be thrown if the connection
            //attempt fails, and an IBM.CTG.GatewayException will be thrown if
            //an error occurs in the Gateway daemon
            using (GatewayConnection gwyConnection = new GatewayConnection(gwyHostName, gwyPort))
            {
                //Prepare the EciRequest
                eciReq            = new EciRequest();
                eciReq.ServerName = cicsServer;
                eciReq.Program    = ProgramName;
                eciReq.ExtendMode = EciExtendMode.EciNoExtend;

                //String commareaString = "L 999999999";
                String commareaString = String.Format("{0}  {1}", "I", STUD_ID);
                commareaString = commareaString.PadRight(CommareaLength);

                //eciReq.SetCommareaData(new byte[CommareaLength]);
                eciReq.SetCommareaData(ASCIIEncoding.ASCII.GetBytes(commareaString));

                //Flow the request
                if (FlowRequest(gwyConnection, eciReq))
                {
                    //Display returned COMMAREA
                    byte[] commarea = eciReq.GetCommareaData();

                    //Display as hex
                    //               Console.Write("  HEX: ");
                    //               for (int i = 0; i < commarea.Length; i++) {
                    //                  Console.Write("{0:x2}", commarea[i]);
                    //               }

                    //Convert the byte data into a string, treating the data
                    //as ASCII encoded characters. This relies on the CICS program
                    //returning ASCII text in the COMMAREA

                    for (int i = 3; i < commarea.Length; i++)
                    {
                        if (commarea[i] == 0)
                        {
                            commarea[i] = 32;
                        }
                    }

                    commareaStr = Encoding.ASCII.GetString(commarea);

                    Console.WriteLine("ASCII: {0}", commareaStr);
                    Console.WriteLine("Message: {0}", commareaStr.Substring(commareaStr.Length - 40, 40));
                }
            }

            Student s    = new Student();
            IntPtr  pBuf = Marshal.StringToBSTR(commareaStr.Substring(3, Student.Size));

            s = (Student)Marshal.PtrToStructure(pBuf, typeof(Student));
            Marshal.FreeBSTR(pBuf);

            return(s);
        }