public static void Main(System.String[] args)
 {
     try
     {
         System.Data.OleDb.OleDbConnection conn = NormativeDatabase.Instance.Connection;
         System.Data.OleDb.OleDbCommand    stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
         System.Data.OleDb.OleDbCommand    temp_OleDbCommand;
         temp_OleDbCommand             = stmt;
         temp_OleDbCommand.CommandText = "select * from TableValues";
         System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();
         while (rs.Read())
         {
             System.Object tabNum = rs.GetValue(1 - 1);
             System.Object val    = rs.GetValue(3 - 1);
             System.Object desc   = rs.GetValue(4 - 1);
             System.Console.Out.WriteLine("Table: " + tabNum + " Value: " + val + " Description: " + desc);
         }
     }
     catch (System.Data.OleDb.OleDbException e)
     {
         log.Error("test msg!!", e);
     }
     catch (System.Exception e)
     {
         log.Error("test msg!!", e);
     }
 }
Пример #2
0
        /*
         * selectAccount selects the account from the database using the current object accountnumber
         */
        public void selectAccount()
        {
            String query = "SELECT * FROM Accounts WHERE AcctNo = '" + AccountNumber + "'";

            dr = db.SelectCommand(query);
            dr.Read();
            accountNumber = AccountNumber;
            CustomerID    = (dr.GetValue(1) + "");
            Type          = (dr.GetValue(2) + "");
            Balance       = (Double.Parse(dr.GetValue(3) + ""));
            db.DBClose();
        }
Пример #3
0
        /*
         * uses the db object to query the db and select the customer info based on customerid
         */
        public void selectCustomer()
        {
            String query = "SELECT * FROM Customers WHERE CustID = '" + CustomerID + "'";

            dr = db.SelectCommand(query);
            dr.Read();
            customerID = CustomerID;
            Password   = (dr.GetValue(1) + "");
            FirstName  = (dr.GetValue(2) + "");
            LastName   = (dr.GetValue(3) + "");
            Address    = (dr.GetValue(4) + "");
            Email      = (dr.GetValue(5) + "");
            db.DBClose();
        }
Пример #4
0
        public static string FetchGivenNamefromExcel(string TestName)
        {
            DirectoryInfo currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());

            path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).Replace("\\bin\\Debug", "") + "\\Input Files\\TestData.xlsx";

            System.Data.OleDb.OleDbConnection MyConnection;

            string sqlTest = null;

            MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "'; Extended Properties='Excel 12.0; HDR = YES'");
            MyConnection.Open();

            sqlTest = "select * from  [" + ObjectRepository.ProjectName + "$] where TestCasesName =\"" + TestName + "\"";
            System.Data.OleDb.OleDbCommand    TestCommand = new System.Data.OleDb.OleDbCommand(sqlTest, MyConnection);
            System.Data.OleDb.OleDbDataReader TestReader  = TestCommand.ExecuteReader();

            GetGivenName = new Dictionary <int, string>();
            while (TestReader.Read())
            {
                int i = 1;
                for (int Row = 1; Row < TestReader.FieldCount; Row++)
                {
                    GetGivenName.Add(i, TestReader.GetValue(Row).ToString().Trim());
                    i++;
                }
            }
            TestReader.Close();
            return(GetGivenName[2].ToString());
        }
Пример #5
0
        /*
         * findAccounts creates a arraylist of all accounts connected to the current customer id
         */
        public void findAccounts()
        {
            String  query = "SELECT * FROM Accounts WHERE Cid = '" + CustomerID + "'";
            Account tempAccount;

            acctList.emptylist();
            dr = db.SelectCommand(query);
            while (dr.Read())
            {
                tempAccount = new Account();
                tempAccount.AccountNumber = dr.GetValue(0) + "";
                tempAccount.CustomerID    = dr.GetValue(1) + "";
                tempAccount.Type          = dr.GetValue(2) + "";
                tempAccount.Balance       = Double.Parse(dr.GetValue(3) + "");
                acctList.addAccount(tempAccount);
            }
            db.DBClose();
        }
Пример #6
0
        //METHODS()
        public void SelectDB(string acctNo)
        {
            DBSetup();                                                             //objects created & connection established
            cmd = "SELECT * FROM Accounts WHERE AcctNo = " + "\"" + acctNo + "\""; //String of SQL command
            //cmd = "SELECT * FROM Accounts WHERE Cid = " + "\"" + acctNo + "\""; //String of SQL command
            OleDbDataAdapter2.SelectCommand.CommandText = cmd;                     //The CommandText  gets  the cmd string
            OleDbDataAdapter2.SelectCommand.Connection  = OleDbConnection2;        //Connection established
            Console.WriteLine(cmd);                                                //Write the  cmd string  to the Console
            try
            {
                OleDbConnection2.Open();                                                                //Open the connection
                System.Data.OleDb.OleDbDataReader dr = OleDbDataAdapter2.SelectCommand.ExecuteReader(); //Assigns "dr" to read the Customers table
                dr.Read();

                //Setting all the data retrieved from the table to the C# classes
                acctNum = acctNo; //Value (0) to get acctNo, the primary key for this table
                c.setCustID(dr.GetValue(1) + "");
                setType(dr.GetValue(2) + "");
                setBalance(Double.Parse(dr.GetValue(3) + ""));
            }
            catch (Exception ex) { Console.WriteLine(ex); } //If an exception is thrown, it goes to the console
            finally { OleDbConnection2.Close(); }           //Closes the connection after everything is done
        }                                                   //end of SELECT
Пример #7
0
 public static void  Main(System.String[] args)
 {
     try
     {
         //UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
         System.Type.GetType("sun.jdbc.odbc.JdbcOdbcDriver");
         //UPGRADE_ISSUE: Method 'java.lang.System.setProperty' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangSystem'"
         //System_Renamed.setProperty("ca.on.uhn.hl7.database.url", "jdbc:odbc:hl7v25");
         // Above line not supported...
         //UPGRADE_NOTE: There are other database providers or managers under System.Data namespace which can be used optionally to better fit the application requirements. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1208'"
         System.Data.OleDb.OleDbConnection conn = NormativeDatabase.Instance.Connection;
         //UPGRADE_TODO: Method 'java.sql.Connection.createStatement' was converted to 'SupportClass.TransactionManager.manager.CreateStatement' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javasqlConnectioncreateStatement'"
         System.Data.OleDb.OleDbCommand stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
         //UPGRADE_TODO: Interface 'java.sql.ResultSet' was converted to 'System.Data.OleDb.OleDbDataReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javasqlResultSet'"
         System.Data.OleDb.OleDbCommand temp_OleDbCommand;
         temp_OleDbCommand             = stmt;
         temp_OleDbCommand.CommandText = "select * from TableValues";
         System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();
         while (rs.Read())
         {
             System.Object tabNum = rs.GetValue(1 - 1);
             System.Object val    = rs.GetValue(3 - 1);
             System.Object desc   = rs.GetValue(4 - 1);
             //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
             System.Console.Out.WriteLine("Table: " + tabNum + " Value: " + val + " Description: " + desc);
         }
     }
     catch (System.Data.OleDb.OleDbException e)
     {
         log.error("test msg!!", e);
     }
     //UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
     catch (System.Exception e)
     {
         log.error("test msg!!", e);
     }
 }
Пример #8
0
        //METHODS()
        public void SelectDB(string id)
        {
            DBSetup();                                                          //objects created & connection established
            cmd = "SELECT * FROM Customers WHERE CustID = " + "\"" + id + "\""; //String of SQL command
            OleDbDataAdapter2.SelectCommand.CommandText = cmd;                  //The CommandText  gets  the cmd string
            OleDbDataAdapter2.SelectCommand.Connection  = OleDbConnection2;     //Connection established
            Console.WriteLine(cmd);                                             //Write the  cmd string  to the Console
            try
            {
                OleDbConnection2.Open();                                                                //Open the connection
                System.Data.OleDb.OleDbDataReader dr = OleDbDataAdapter2.SelectCommand.ExecuteReader(); //Assigns "dr" to read the Customers table
                dr.Read();

                //Setting all the data retrieved from the table to the C# classes
                cid = id; //Value (0) to get CustID
                setPassword(dr.GetValue(1) + "");
                setFname(dr.GetValue(2) + "");
                setLname(dr.GetValue(3) + "");
                addr.setState(dr.GetValue(4) + "");
                setEmail(dr.GetValue(5) + "");
            }
            catch (Exception ex) { Console.WriteLine(ex); } //If an exception is thrown, it goes to the console
            finally { OleDbConnection2.Close(); }           //Closes the connection after everything is done
        }                                                   //end of SELECT
Пример #9
0
        /// <summary> Returns the Java source code for a class that represents the specified segment.</summary>
        public static System.String makeSegment(System.String name, System.String version)
        {
            Console.WriteLine("Making segment " + name);
            System.Text.StringBuilder source = new System.Text.StringBuilder();
            try
            {
                //UPGRADE_NOTE: There are other database providers or managers under System.Data namespace which can be used optionally to better fit the application requirements. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1208'"
                System.Collections.ArrayList elements = new System.Collections.ArrayList();
                SegmentElement se;
                System.String  segDesc = null;
                using (System.Data.OleDb.OleDbConnection conn = NormativeDatabase.Instance.Connection)
                {
                    System.Text.StringBuilder sql = new System.Text.StringBuilder();
                    sql.Append("SELECT HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no, ");
                    sql.Append("HL7SegmentDataElements.repetitional, HL7SegmentDataElements.repetitions, ");
                    sql.Append("HL7DataElements.description, HL7DataElements.length, HL7DataElements.table_id, ");
                    sql.Append("HL7SegmentDataElements.req_opt, HL7Segments.description, HL7DataElements.data_structure ");
                    sql.Append("FROM HL7Versions RIGHT JOIN (HL7Segments INNER JOIN (HL7DataElements INNER JOIN HL7SegmentDataElements ");
                    sql.Append("ON (HL7DataElements.version_id = HL7SegmentDataElements.version_id) ");
                    sql.Append("AND (HL7DataElements.data_item = HL7SegmentDataElements.data_item)) ");
                    sql.Append("ON (HL7Segments.version_id = HL7SegmentDataElements.version_id) ");
                    sql.Append("AND (HL7Segments.seg_code = HL7SegmentDataElements.seg_code)) ");
                    sql.Append("ON (HL7Versions.version_id = HL7Segments.version_id) ");
                    sql.Append("WHERE HL7SegmentDataElements.seg_code = '");
                    sql.Append(name);
                    sql.Append("' and HL7Versions.hl7_version = '");
                    sql.Append(version);
                    sql.Append("' ORDER BY HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no;");
                    //System.out.println(sql.toString());  //for debugging
                    //UPGRADE_TODO: Method 'java.sql.Connection.createStatement' was converted to 'SupportClass.TransactionManager.manager.CreateStatement' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javasqlConnectioncreateStatement'"
                    System.Data.OleDb.OleDbCommand stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
                    //UPGRADE_TODO: Interface 'java.sql.ResultSet' was converted to 'System.Data.OleDb.OleDbDataReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javasqlResultSet'"
                    System.Data.OleDb.OleDbCommand temp_OleDbCommand;
                    temp_OleDbCommand             = stmt;
                    temp_OleDbCommand.CommandText = sql.ToString();
                    System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();

                    while (rs.Read())
                    {
                        if (segDesc == null)
                        {
                            segDesc = System.Convert.ToString(rs[9 - 1]);
                        }
                        se       = new SegmentElement();
                        se.field = Convert.ToInt32(rs.GetValue(2 - 1));
                        se.rep   = System.Convert.ToString(rs[3 - 1]);
                        if (rs.IsDBNull(4 - 1))
                        {
                            se.repetitions = 0;
                        }
                        else
                        {
                            se.repetitions = Convert.ToInt32(rs.GetValue(4 - 1));
                        }

                        if (se.repetitions == 0)
                        {
                            if (se.rep == null || !se.rep.ToUpper().Equals("Y".ToUpper()))
                            {
                                se.repetitions = 1;
                            }
                        }
                        se.desc = System.Convert.ToString(rs[5 - 1]);
                        if (!rs.IsDBNull(6 - 1))
                        {
                            se.length = Convert.ToInt32(rs.GetValue(6 - 1));
                        }
                        se.table = Convert.ToInt32(rs.GetValue(7 - 1));
                        se.opt   = System.Convert.ToString(rs[8 - 1]);
                        se.type  = System.Convert.ToString(rs[10 - 1]);
                        //shorten CE_x to CE
                        if (se.type.StartsWith("CE"))
                        {
                            se.type = "CE";
                        }

                        elements.Add(se);

                        /*System.out.println("Segment: " + name + " Field: " + se.field + " Rep: " + se.rep +
                         * " Repetitions: " + se.repetitions + " Desc: " + se.desc + " Length: " + se.length +
                         * " Table: " + se.table + " Segment Desc: " + segDesc);*/
                    }
                    rs.Close();
                    //UPGRADE_ISSUE: Method 'java.sql.Statement.close' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javasqlStatementclose'"
                    stmt.Dispose();
                    NormativeDatabase.Instance.returnConnection(conn);
                }

                //write imports, class documentation, etc ...
                source.Append("using System;\r\n");
                source.Append("using ca.uhn.hl7v2.model;\r\n");
                source.Append("using ");
                source.Append(SourceGenerator.getVersionPackageName(version));
                source.Append("datatype;\r\n\r\n");
                source.Append("using ca.uhn.log;\r\n");
                source.Append("using ca.uhn.hl7v2.parser;\r\n");
                source.Append("using ca.uhn.hl7v2;\r\n\r\n");

                source.Append("namespace ");
                source.Append(SourceGenerator.getVersionPackageName(version));
                source.Append("segment{\r\n\r\n");
                source.Append("/**\r\n");
                source.Append(" * <p>Represents an HL7 ");
                source.Append(name);
                source.Append(" message segment. \r\n");
                source.Append(" * This segment has the following fields:</p><p>\r\n");
                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    source.Append(" * ");
                    source.Append(name);
                    source.Append("-");
                    source.Append(se.field);
                    source.Append(": ");
                    source.Append(se.desc);
                    source.Append(" (");
                    source.Append(se.type);
                    source.Append(")<br> \r\n");
                }
                source.Append(" * </p><p>The get...() methods return data from individual fields.  These methods \r\n");
                source.Append(" * do not throw exceptions and may therefore have to handle exceptions internally.  \r\n");
                source.Append(" * If an exception is handled internally, it is logged and null is returned.  \r\n");
                source.Append(" * This is not expected to happen - if it does happen this indicates not so much \r\n");
                source.Append(" * an exceptional circumstance as a bug in the code for this class.</p>    \r\n");
                source.Append(" */\r\n");
                source.Append("[Serializable]\r\n");
                source.Append("public class ");
                source.Append(name);
                source.Append(" : AbstractSegment ");

                //implement interface from model.control package if required

                /*Class correspondingControlInterface = Control.getInterfaceImplementedBy(name);
                 * if (correspondingControlInterface != null) {
                 * source.append("implements ");
                 * source.append(correspondingControlInterface.getName());
                 * } */

                source.Append(" {\r\n\r\n");
                source.Append("  /**\r\n");
                source.Append("   * Creates a ");
                source.Append(name);
                source.Append(" (");
                source.Append(segDesc);
                source.Append(") segment object that belongs to the given \r\n");
                source.Append("   * message.  \r\n");
                source.Append("   */\r\n");

                //write constructor
                source.Append("  public ");
                source.Append(name);
                source.Append("(Group parent, ModelClassFactory factory) : base(parent,factory) {\r\n");
                source.Append("    Message message = Message;\r\n");
                if (elements.Count > 0)
                {
                    source.Append("    try {\r\n");
                    for (int i = 0; i < elements.Count; i++)
                    {
                        se = (SegmentElement)elements[i];
                        System.String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("       this.add(");
                        source.Append("typeof(" + type + ")");
                        //                    if (type.equalsIgnoreCase("Varies")) {
                        //                    } else {
                        //                        source.append("factory.getTypeClass(\"");
                        //                        source.append(type);
                        //                        source.append("\", \"");
                        //                        source.append(version);
                        //                        source.append("\")");
                        //                    }
                        source.Append(", ");
                        if (se.opt == null)
                        {
                            source.Append("false");
                        }
                        else
                        {
                            if (se.opt.ToUpper().Equals("R".ToUpper()))
                            {
                                source.Append("true");
                            }
                            else
                            {
                                source.Append("false");
                            }
                        }
                        source.Append(", ");
                        source.Append(se.repetitions);
                        source.Append(", ");
                        source.Append(se.length);
                        source.Append(", ");
                        if (se.type.Equals("ID") || se.type.Equals("IS"))
                        {
                            source.Append("new System.Object[]{message, ");
                            source.Append(se.table);
                            source.Append("}");
                        }
                        else
                        {
                            source.Append("new System.Object[]{message}");
                        }
                        if (se.desc != null && se.desc.Trim().Length > 0)
                        {
                            source.Append(", ");


                            source.Append("\"" + se.GetDescriptionWithoutSpecialCharacters() + "\"");
                        }
                        source.Append(");\r\n");
                    }
                    source.Append("    } catch (HL7Exception he) {\r\n");
                    source.Append("        HapiLogFactory.getHapiLog(GetType()).error(\"Can't instantiate \" + this.getStructureName(), he);\r\n");
                    source.Append("    }\r\n");
                }
                source.Append("  }\r\n\r\n");

                //write a datatype-specific accessor for each field
                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    if (!se.desc.ToUpper().Equals("UNUSED".ToUpper()))
                    {
                        //some entries in 2.1 DB say "unused"
                        System.String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("\t/**\r\n");
                        source.Append("\t* Returns ");
                        if (se.repetitions != 1)
                        {
                            source.Append("a single repetition of ");
                        }
                        source.Append(se.desc);
                        source.Append("(");
                        source.Append(name);
                        source.Append("-");
                        source.Append(se.field);
                        source.Append(").\r\n");
                        if (se.repetitions != 1)
                        {
                            source.Append("\t* @param rep the repetition number (this is a repeating field)\r\n");
                            source.Append("\t* @throws HL7Exception if the repetition number is invalid.\r\n");
                        }
                        source.Append("\t*/\r\n");
                        source.Append("\tpublic ");
                        source.Append(type);
                        source.Append(" ");
                        source.Append(SourceGenerator.makeAccessorNameCSharp(se.desc, se.repetitions));
                        if (se.repetitions != 1)
                        {
                            source.Append("(int rep)");
                        }
                        source.Append("\n\t{\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\tget{\r\n");
                        }
                        source.Append("\t\t\t");
                        source.Append(type);
                        source.Append(" ret = null;\r\n");
                        source.Append("\t\t\ttry\n\t\t\t{\r\n");
                        source.Append("\t\t\tType t = this.getField(");
                        source.Append(se.field);
                        source.Append(", ");
                        if (se.repetitions == 1)
                        {
                            source.Append("0");
                        }
                        else
                        {
                            source.Append("rep");
                        }
                        source.Append(");\r\n");
                        source.Append("\t\t\t\tret = (");
                        source.Append(type);
                        source.Append(")t;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\t\t}\n\t\t\t catch (HL7Exception he) {\r\n");
                            source.Append("\t\t\tHapiLogFactory.getHapiLog(GetType()).error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                        }
                        source.Append("\t\t} catch (System.Exception ex) {\r\n");
                        source.Append("\t\t\tHapiLogFactory.getHapiLog(GetType()).error(\"Unexpected problem obtaining field value.  This is a bug.\", ex);\r\n");
                        source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", ex);\r\n");
                        source.Append("    }\r\n");
                        source.Append("\t\t\treturn ret;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t}\r\n");                             //End get
                        }
                        source.Append("  }\r\n\r\n");


                        //add an array accessor as well for repeating fields
                        if (se.repetitions != 1)
                        {
                            source.Append("  /**\r\n");
                            source.Append("   * Returns all repetitions of ");
                            source.Append(se.desc);
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   */\r\n");
                            source.Append("  public ");
                            source.Append(type);
                            source.Append("[] ");
                            source.Append(SourceGenerator.makeAccessorName(se.desc));
                            source.Append("() {\r\n");
                            source.Append("     ");
                            source.Append(type);
                            source.Append("[] ret = null;\r\n");
                            source.Append("    try {\r\n");
                            source.Append("        Type[] t = this.getField(");
                            source.Append(se.field);
                            source.Append(");  \r\n");
                            source.Append("        ret = new ");
                            source.Append(type);
                            source.Append("[t.Length];\r\n");
                            source.Append("        for (int i = 0; i < ret.Length; i++) {\r\n");
                            source.Append("            ret[i] = (");
                            source.Append(type);
                            source.Append(")t[i];\r\n");
                            source.Append("        }\r\n");
                            source.Append("    } catch (HL7Exception he) {\r\n");
                            source.Append("        HapiLogFactory.getHapiLog(this.GetType()).error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                            source.Append("    } catch (System.Exception cce) {\r\n");
                            source.Append("        HapiLogFactory.getHapiLog(GetType()).error(\"Unexpected problem obtaining field value.  This is a bug.\", cce);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", cce);\r\n");
                            source.Append("  }\r\n");
                            source.Append(" return ret;\r\n");
                            source.Append("}\r\n\r\n");
                        }
                    }
                }

                //add adapter method code for control package if it exists
                //source.append(Control.getImplementation(correspondingControlInterface, version));

                source.Append("\n}");
            }
            catch (System.Data.OleDb.OleDbException sqle)
            {
                SupportClass.WriteStackTrace(sqle, Console.Error);
            }

            return(source.ToString());
        }
Пример #10
0
 public object GetObject(System.Data.OleDb.OleDbDataReader reader, int i)
 {
     return(reader.GetValue(i));
 }
        /// <summary> Returns the Java source code for a class that represents the specified segment.</summary>
        public static System.String makeSegment(System.String name, System.String version)
        {
            Console.WriteLine("Making segment " + name);
            System.Text.StringBuilder source = new System.Text.StringBuilder();
            try
            {
                System.Collections.ArrayList elements = new System.Collections.ArrayList();
                SegmentElement se;
                System.String  segDesc = null;
                using (System.Data.OleDb.OleDbConnection conn = NormativeDatabase.Instance.Connection)
                {
                    System.Text.StringBuilder sql = new System.Text.StringBuilder();
                    sql.Append("SELECT HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no, ");
                    sql.Append("HL7SegmentDataElements.repetitional, HL7SegmentDataElements.repetitions, ");
                    sql.Append("HL7DataElements.description, HL7DataElements.length, HL7DataElements.table_id, ");
                    sql.Append("HL7SegmentDataElements.req_opt, HL7Segments.description, HL7DataElements.data_structure ");
                    sql.Append("FROM HL7Versions RIGHT JOIN (HL7Segments INNER JOIN (HL7DataElements INNER JOIN HL7SegmentDataElements ");
                    sql.Append("ON (HL7DataElements.version_id = HL7SegmentDataElements.version_id) ");
                    sql.Append("AND (HL7DataElements.data_item = HL7SegmentDataElements.data_item)) ");
                    sql.Append("ON (HL7Segments.version_id = HL7SegmentDataElements.version_id) ");
                    sql.Append("AND (HL7Segments.seg_code = HL7SegmentDataElements.seg_code)) ");
                    sql.Append("ON (HL7Versions.version_id = HL7Segments.version_id) ");
                    sql.Append("WHERE HL7SegmentDataElements.seg_code = '");
                    sql.Append(name);
                    sql.Append("' and HL7Versions.hl7_version = '");
                    sql.Append(version);
                    sql.Append("' ORDER BY HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no;");
                    System.Data.OleDb.OleDbCommand stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
                    System.Data.OleDb.OleDbCommand temp_OleDbCommand;
                    temp_OleDbCommand             = stmt;
                    temp_OleDbCommand.CommandText = sql.ToString();
                    System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();

                    while (rs.Read())
                    {
                        if (segDesc == null)
                        {
                            segDesc = System.Convert.ToString(rs[9 - 1]);
                        }
                        se       = new SegmentElement();
                        se.field = Convert.ToInt32(rs.GetValue(2 - 1));
                        se.rep   = System.Convert.ToString(rs[3 - 1]);
                        if (rs.IsDBNull(4 - 1))
                        {
                            se.repetitions = 0;
                        }
                        else
                        {
                            se.repetitions = Convert.ToInt32(rs.GetValue(4 - 1));
                        }

                        if (se.repetitions == 0)
                        {
                            if (se.rep == null || !se.rep.ToUpper().Equals("Y".ToUpper()))
                            {
                                se.repetitions = 1;
                            }
                        }
                        se.desc = System.Convert.ToString(rs[5 - 1]);
                        if (!rs.IsDBNull(6 - 1))
                        {
                            se.length = Convert.ToInt32(rs.GetValue(6 - 1));
                        }
                        se.table = Convert.ToInt32(rs.GetValue(7 - 1));
                        se.opt   = System.Convert.ToString(rs[8 - 1]);
                        se.type  = System.Convert.ToString(rs[10 - 1]);
                        //shorten CE_x to CE
                        if (se.type.StartsWith("CE"))
                        {
                            se.type = "CE";
                        }

                        elements.Add(se);

                        /*System.out.println("Segment: " + name + " Field: " + se.field + " Rep: " + se.rep +
                         * " Repetitions: " + se.repetitions + " Desc: " + se.desc + " Length: " + se.length +
                         * " Table: " + se.table + " Segment Desc: " + segDesc);*/
                    }
                    rs.Close();
                    stmt.Dispose();
                    NormativeDatabase.Instance.returnConnection(conn);
                }

                //write imports, class documentation, etc ...
                source.Append("using System;\r\n");
                source.Append("using NHapi.Base;\r\n");
                source.Append("using NHapi.Base.Parser;\r\n");
                source.Append("using NHapi.Base.Model;\r\n");
                source.Append("using ");
                source.Append(PackageManager.GetVersionPackageName(version));
                source.Append("Datatype;\r\n");
                source.Append("using NHapi.Base.Log;\r\n\r\n");

                source.Append("namespace ");
                source.Append(PackageManager.GetVersionPackageName(version));
                source.Append("Segment{\r\n\r\n");
                source.Append("///<summary>\r\n");
                source.Append("/// Represents an HL7 ");
                source.Append(name);
                source.Append(" message segment. \r\n");
                source.Append("/// This segment has the following fields:<ol>\r\n");
                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    source.Append("///");
                    source.Append("<li>");
                    source.Append(name);
                    source.Append("-");
                    source.Append(se.field);
                    source.Append(": ");
                    source.Append(se.GetDescriptionWithoutSpecialCharacters());
                    source.Append(" (");
                    source.Append(se.type);
                    source.Append(")</li>\r\n");
                }
                source.Append("///</ol>\r\n");
                source.Append("/// The get...() methods return data from individual fields.  These methods \r\n");
                source.Append("/// do not throw exceptions and may therefore have to handle exceptions internally.  \r\n");
                source.Append("/// If an exception is handled internally, it is logged and null is returned.  \r\n");
                source.Append("/// This is not expected to happen - if it does happen this indicates not so much \r\n");
                source.Append("/// an exceptional circumstance as a bug in the code for this class.\r\n");
                source.Append("///</summary>\r\n");
                source.Append("[Serializable]\r\n");
                source.Append("public class ");
                source.Append(name);
                source.Append(" : AbstractSegment ");

                //implement interface from Model.control package if required

                /*Class correspondingControlInterface = Control.getInterfaceImplementedBy(name);
                 * if (correspondingControlInterface != null) {
                 * source.append("implements ");
                 * source.append(correspondingControlInterface.getName());
                 * } */

                source.Append(" {\r\n\r\n");
                source.Append("  /**\r\n");
                source.Append("   * Creates a ");
                source.Append(name);
                source.Append(" (");
                source.Append(segDesc);
                source.Append(") segment object that belongs to the given \r\n");
                source.Append("   * message.  \r\n");
                source.Append("   */\r\n");

                //write constructor
                source.Append("\tpublic ");
                source.Append(name);
                source.Append("(IGroup parent, IModelClassFactory factory) : base(parent,factory) {\r\n");
                source.Append("\tIMessage message = Message;\r\n");
                if (elements.Count > 0)
                {
                    source.Append("    try {\r\n");
                    for (int i = 0; i < elements.Count; i++)
                    {
                        se = (SegmentElement)elements[i];
                        System.String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("       this.add(");
                        source.Append("typeof(" + type + ")");
                        //                    if (type.equalsIgnoreCase("Varies")) {
                        //                    } else {
                        //                        source.append("factory.getTypeClass(\"");
                        //                        source.append(type);
                        //                        source.append("\", \"");
                        //                        source.append(version);
                        //                        source.append("\")");
                        //                    }
                        source.Append(", ");
                        if (se.opt == null)
                        {
                            source.Append("false");
                        }
                        else
                        {
                            if (se.opt.ToUpper().Equals("R".ToUpper()))
                            {
                                source.Append("true");
                            }
                            else
                            {
                                source.Append("false");
                            }
                        }
                        source.Append(", ");
                        source.Append(se.repetitions);
                        source.Append(", ");
                        source.Append(se.length);
                        source.Append(", ");
                        if (se.type.Equals("ID") || se.type.Equals("IS"))
                        {
                            source.Append("new System.Object[]{message, ");
                            source.Append(se.table);
                            source.Append("}");
                        }
                        else
                        {
                            source.Append("new System.Object[]{message}");
                        }
                        if (se.desc != null && se.desc.Trim().Length > 0)
                        {
                            source.Append(", ");


                            source.Append("\"" + se.GetDescriptionWithoutSpecialCharacters() + "\"");
                        }
                        source.Append(");\r\n");
                    }
                    source.Append("    } catch (HL7Exception he) {\r\n");
                    source.Append("        HapiLogFactory.GetHapiLog(GetType()).Error(\"Can't instantiate \" + GetType().Name, he);\r\n");
                    source.Append("    }\r\n");
                }
                source.Append("  }\r\n\r\n");

                //write a datatype-specific accessor for each field
                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    if (!se.desc.ToUpper().Equals("UNUSED".ToUpper()))
                    {
                        //some entries in 2.1 DB say "unused"
                        System.String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("\t///<summary>\r\n");
                        source.Append("\t/// Returns ");
                        if (se.repetitions != 1)
                        {
                            source.Append("a single repetition of ");
                        }
                        source.Append(se.GetDescriptionWithoutSpecialCharacters());
                        source.Append("(");
                        source.Append(name);
                        source.Append("-");
                        source.Append(se.field);
                        source.Append(").\r\n");
                        if (se.repetitions != 1)
                        {
                            source.Append("\t/// throws HL7Exception if the repetition number is invalid.\r\n");
                            source.Append("\t/// <param name=\"rep\">The repetition number (this is a repeating field)</param>\r\n");
                        }
                        source.Append("\t///</summary>\r\n");
                        source.Append("\tpublic ");
                        source.Append(type);
                        source.Append(" ");
                        source.Append(SourceGenerator.MakeAccessorName(se.desc, se.repetitions));
                        if (se.repetitions != 1)
                        {
                            source.Append("(int rep)");
                        }
                        source.Append("\n\t{\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\tget{\r\n");
                        }
                        source.Append("\t\t\t");
                        source.Append(type);
                        source.Append(" ret = null;\r\n");
                        source.Append("\t\t\ttry\n\t\t\t{\r\n");
                        source.Append("\t\t\tIType t = this.GetField(");
                        source.Append(se.field);
                        source.Append(", ");
                        if (se.repetitions == 1)
                        {
                            source.Append("0");
                        }
                        else
                        {
                            source.Append("rep");
                        }
                        source.Append(");\r\n");
                        source.Append("\t\t\t\tret = (");
                        source.Append(type);
                        source.Append(")t;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\t\t}\n\t\t\t catch (HL7Exception he) {\r\n");
                            source.Append("\t\t\tHapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                        }
                        source.Append("\t\t} catch (System.Exception ex) {\r\n");
                        source.Append("\t\t\tHapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", ex);\r\n");
                        source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", ex);\r\n");
                        source.Append("    }\r\n");
                        source.Append("\t\t\treturn ret;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t}\r\n"); //End get
                        }
                        source.Append("  }\r\n\r\n");


                        //add an array accessor as well for repeating fields
                        if (se.repetitions != 1)
                        {
                            source.Append("  ///<summary>\r\n");
                            source.Append("  /// Returns all repetitions of ");
                            source.Append(se.GetDescriptionWithoutSpecialCharacters());
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   ///</summary>\r\n");
                            source.Append("  public ");
                            source.Append(type);
                            source.Append("[] Get");
                            source.Append(SourceGenerator.MakeAccessorName(se.desc));
                            source.Append("() {\r\n");
                            source.Append("     ");
                            source.Append(type);
                            source.Append("[] ret = null;\r\n");
                            source.Append("    try {\r\n");
                            source.Append("        IType[] t = this.GetField(");
                            source.Append(se.field);
                            source.Append(");  \r\n");
                            source.Append("        ret = new ");
                            source.Append(type);
                            source.Append("[t.Length];\r\n");
                            source.Append("        for (int i = 0; i < ret.Length; i++) {\r\n");
                            source.Append("            ret[i] = (");
                            source.Append(type);
                            source.Append(")t[i];\r\n");
                            source.Append("        }\r\n");
                            source.Append("    } catch (HL7Exception he) {\r\n");
                            source.Append("        HapiLogFactory.GetHapiLog(this.GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                            source.Append("    } catch (System.Exception cce) {\r\n");
                            source.Append("        HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", cce);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", cce);\r\n");
                            source.Append("  }\r\n");
                            source.Append(" return ret;\r\n");
                            source.Append("}\r\n\r\n");

                            //Add property for the total repetitions of this object
                            source.Append("  ///<summary>\r\n");
                            source.Append("  /// Returns the total repetitions of ");
                            source.Append(se.GetDescriptionWithoutSpecialCharacters());
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   ///</summary>\r\n");
                            source.Append("  public int ");
                            source.Append(SourceGenerator.MakeName(se.desc));
                            source.Append("RepetitionsUsed\r\n");
                            source.Append("{\r\n");
                            source.Append("get{\r\n");
                            source.Append("    try {\r\n");
                            source.Append("\treturn GetTotalFieldRepetitionsUsed(" + se.field + ");\r\n");
                            source.Append("    }\r\n");
                            source.Append("catch (HL7Exception he) {\r\n");
                            source.Append("        HapiLogFactory.GetHapiLog(this.GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                            source.Append("} catch (System.Exception cce) {\r\n");
                            source.Append("        HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", cce);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", cce);\r\n");
                            source.Append("}\r\n");
                            source.Append("}\r\n");
                            source.Append("}\r\n");
                        }
                    }
                }

                //add adapter method code for control package if it exists
                //source.append(Control.getImplementation(correspondingControlInterface, version));

                source.Append("\n}");
            }
            catch (System.Data.OleDb.OleDbException sqle)
            {
                SupportClass.WriteStackTrace(sqle, Console.Error);
            }

            return(source.ToString());
        }
Пример #12
0
        protected CalendarEvent _CreateEventFromData(System.Data.OleDb.OleDbDataReader pEventData, Boolean bRException)
        {
            try
            {
                CalendarEvent pEvent = null;
                int           nEventID;

                if (pEventData.IsClosed /*|| !pEventData.HasRows*/)
                {
                    return(null);
                }

                nEventID = pEventData.GetInt32(pEventData.GetOrdinal("EventID"));
                pEvent   = m_pCalendar.DataProvider.CreateEventEx(nEventID);

                if (pEvent == null)
                {
                    return(null);
                }

                pEvent.Subject  = pEventData.GetString(pEventData.GetOrdinal("Subject"));
                pEvent.Location = pEventData.GetString(pEventData.GetOrdinal("Location"));
                pEvent.Body     = pEventData.GetString(pEventData.GetOrdinal("Body"));

                pEvent.MeetingFlag = ToBool(pEventData.GetInt32(pEventData.GetOrdinal("IsMeeting")));
                pEvent.PrivateFlag = ToBool(pEventData.GetInt32(pEventData.GetOrdinal("IsPrivate")));

                pEvent.Label      = pEventData.GetInt32(pEventData.GetOrdinal("LabelID"));
                pEvent.BusyStatus = (CalendarEventBusyStatus)pEventData.GetInt32(pEventData.GetOrdinal("BusyStatus"));
                pEvent.Importance = (CalendarEventImportance)pEventData.GetInt32(pEventData.GetOrdinal("ImportanceLevel"));

                pEvent.StartTime = pEventData.GetDateTime(pEventData.GetOrdinal("StartDateTime"));
                pEvent.EndTime   = pEventData.GetDateTime(pEventData.GetOrdinal("EndDateTime"));

                pEvent.AllDayEvent = ToBool(pEventData.GetInt32(pEventData.GetOrdinal("IsAllDayEvent")));

                pEvent.Reminder = ToBool(pEventData.GetInt32(pEventData.GetOrdinal("IsReminder")));
                pEvent.ReminderMinutesBeforeStart = pEventData.GetInt32(pEventData.GetOrdinal("ReminderMinutesBeforeStart"));
                pEvent.ReminderSoundFile          = pEventData.GetString(pEventData.GetOrdinal("RemainderSoundFile"));

                pEvent.CustomProperties.LoadFromString(pEventData.GetString(pEventData.GetOrdinal("CustomPropertiesXMLData")));
                pEvent.CustomIcons.LoadFromString(pEventData.GetString(pEventData.GetOrdinal("CustomIconsIDs")));

                pEvent.ScheduleID = pEventData.GetInt32(pEventData.GetOrdinal("ScheduleID"));

                if (bRException)
                {
                    pEvent.MakeAsRException();

                    pEvent.RExceptionStartTimeOrig = pEventData.GetDateTime(pEventData.GetOrdinal("RExceptionStartTimeOrig"));
                    pEvent.RExceptionEndTimeOrig   = pEventData.GetDateTime(pEventData.GetOrdinal("RExceptionEndTimeOrig"));
                    pEvent.RExceptionDeleted       = ToBool(pEventData.GetInt32(pEventData.GetOrdinal("ISRecurrenceExceptionDeleted")));
                }

                if (!bRException)
                {
                    //	"process_RecurrenceState" and "process_RecurrencePatternID" properties
                    //	 are used to process master events.
                    //
                    //	 If they are set and RecurrenceStaie is Master Data provider will
                    //	 fier DoReadRPattern event and make event as Master.
                    //	 And it will also generate occurrences for RetrieveDayEvents method.
                    //
                    //	 These properties are temporary and they will be removed by data provider.
                    //
                    //	 If these properties are not set data provider expect that master event
                    //	 is already compleated - CreateRecurrence method is called and
                    //	 Recurrence pattern is set.
                    //
                    //	 This mechanism is useful for DB data providers, when events and patterns
                    //	 are stored separately (in tables).
                    //	 But if events stored in some memory collection or array
                    //	 it should not be used because master event store recurrence pattern inside.

                    pEvent.CustomProperties["process_RecurrenceState"]     = pEventData.GetValue(pEventData.GetOrdinal("RecurrenceState"));
                    pEvent.CustomProperties["process_RecurrencePatternID"] = pEventData.GetValue(pEventData.GetOrdinal("RecurrencePatternID"));
                }

                return(pEvent);
            }
            catch (System.Exception e)
            {
                System.Diagnostics.Debug.WriteLine("EXCEPTION! SQLDataHelper.CreateEventFromRS: " + e.Message);
            }

            return(null);
        }