예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
                conn_str.UserID         = "user";
                conn_str.Password       = "******";
                conn_str.Server         = "localhost";
                conn_str.Database       = "HS.SALES";
                conn_str.ServerType     = "UNIVERSE";
                conn_str.AccessMode     = "Native"; // FOR UO
                conn_str.RpcServiceType = "uvcs";   // FOR UO
                conn_str.Pooling        = false;
                string       s   = conn_str.ToString();
                U2Connection con = new U2Connection();
                con.ConnectionString = s;
                con.Open();
                Console.WriteLine("Connected.........................");

                // get RECID

                UniSession us1 = con.UniSession;

                UniSelectList sl = us1.CreateUniSelectList(2);

                // Select UniFile
                UniFile fl = us1.CreateUniFile("CUSTOMER");
                sl.Select(fl);

                bool          lLastRecord = sl.LastRecordRead;
                List <string> lRecIdList  = new List <string>();
                while (!lLastRecord)
                {
                    string sRecID = sl.Next();
                    lRecIdList.Add(sRecID);
                    Console.WriteLine("Record ID:" + sRecID);
                    lLastRecord = sl.LastRecordRead;
                }

                UniDataSet uSet = fl.ReadRecords(lRecIdList.ToArray());
                // use for each statement to print the record
                foreach (UniRecord item in uSet)
                {
                    Console.WriteLine(item.ToString());
                }

                con.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Console.WriteLine("Enter to exit:");
                string line = Console.ReadLine();
            }
        }
예제 #2
0
        public static CssFileResult GetData(AccountList list, CssAccountFile file, CssCredentials cssCredentials)
        {
            var lHostName    = cssCredentials.Hostname;
            var lAccount     = cssCredentials.Account;
            var lUser        = cssCredentials.User;
            var lPassword    = cssCredentials.UserPassword;
            var lServiceType = cssCredentials.ServiceType;

            var response    = new CssFileResult();
            var fileResults = new CssFile {
                FileName = list.AccountListName
            };

            UniSession us = null;

            try
            {
                //get the session object
                us = UniObjects.OpenSession(lHostName, lUser, lPassword, lAccount, lServiceType);

                // create select list
                UniSelectList selectList = us.CreateUniSelectList(2);
                selectList.GetList(list.AccountListName);

                // read records using array of records ids
                var ids = selectList.ReadListAsStringArray();

                //open file
                UniFile cssFile = us.CreateUniFile(file.FileName);
                var     lSet    = cssFile.ReadRecords(ids);

                //var dict = us.CreateUniDictionary(file.FileName);
                //var field1 = dict.ReadField(1);

                //use foreach statement to construct data to be displayed
                foreach (UniRecord item in lSet)
                {
                    var record    = new CssRecord(item.RecordID, "");
                    var numFields = item.Record.Dcount();
                    for (int i = 0; i < numFields; i++)
                    {
                        var field = item.Record.Extract(i);

                        var valuesCount = field.Dcount();
                        if (valuesCount > 1)
                        {
                            throw new Exception("This field has sub-values" + field);
                        }
                        record.Fields.Add(new CssField(i.ToString(), field.ToString()));
                    }
                    fileResults.Records.Add(record);
                }

                response.FileContents = fileResults;

                return(response);
            }
            catch (Exception ex)
            {
                response.CssResponses.Results.Add(new CommandResponse("Exception", ex.ToString()));
            }
            finally
            {
                if (us != null && us.IsActive)
                {
                    UniObjects.CloseSession(us);
                }
            }
            response.CssResponses.Results.Add(new CommandResponse("Error", "There was an error procesing your request."));
            return(response);
        }
예제 #3
0
        static void Main(string[] args)
        {
            try
            {
                U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
                conn_str.UserID         = "user";
                conn_str.Password       = "******";
                conn_str.Server         = "localhost";
                conn_str.Database       = "demo";
                conn_str.ServerType     = "UNIDATA";
                conn_str.AccessMode     = "Native"; // FOR UO
                conn_str.RpcServiceType = "udcs";   // FOR UO
                conn_str.Pooling        = false;
                string       s   = conn_str.ToString();
                U2Connection con = new U2Connection();
                con.ConnectionString = s;
                con.Open();
                Console.WriteLine("Connected.........................");
                UniSession us1 = con.UniSession;

                UniSelectList sl = us1.CreateUniSelectList(2);
                // Select UniFile
                UniFile fl = us1.CreateUniFile("STUDENT");
                sl.Select(fl);

                // read records as unidataset
                string[]   sArray = { "291222021", "521814564", "424325656" };
                UniDataSet uSet   = fl.ReadRecords(sArray);

                // use for each statement to print the record
                foreach (UniRecord item in uSet)
                {
                    Console.WriteLine(item.ToString());
                }

                // use index to print the record
                int lCount = uSet.RowCount;
                for (int ii = 0; ii < lCount; ii++)
                {
                    UniRecord ee = uSet[ii];
                    Console.WriteLine(ee.ToString());
                }

                // print one by one record
                UniRecord q2  = uSet["291222021"];
                string    sq2 = q2.ToString();
                Console.WriteLine("  Record data for rec id 291222021:" + sq2);
                UniRecord q3  = uSet["521814564"];
                string    sq3 = q3.ToString();
                Console.WriteLine("  Record data for rec id 521814564:" + sq3);
                UniRecord q4  = uSet["424325656"];
                string    sq4 = q4.ToString();
                Console.WriteLine("  Record data for rec id 424325656:" + sq4);

                //create UniDataSet in the Client Side
                UniDataSet uSet3 = us1.CreateUniDataSet();
                uSet3.Insert("3", "aaa");
                uSet3.Insert("4", "bbb");
                uSet3.Insert("5", "vvv");
                uSet3.Insert(2, "8", "www");



                con.Close();
            }
            catch (Exception e)
            {
                string s = e.Message;
                if (e.InnerException != null)
                {
                    s += e.InnerException.Message;
                }

                Console.WriteLine(s);
            }
            finally
            {
                Console.WriteLine("Enter to exit:");
                string line = Console.ReadLine();
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            try
            {
                U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
                conn_str.UserID         = "user";
                conn_str.Password       = "******";
                conn_str.Server         = "localhost";
                conn_str.Database       = "HS.SALES";
                conn_str.ServerType     = "UNIVERSE";
                conn_str.AccessMode     = "Native"; // FOR UO
                conn_str.RpcServiceType = "uvcs";   // FOR UO
                conn_str.Pooling        = false;
                string       s   = conn_str.ToString();
                U2Connection con = new U2Connection();
                con.ConnectionString = s;
                con.Open();
                Console.WriteLine("Connected.........................");

                // get RECID

                UniSession us1 = con.UniSession;

                // open customer file
                UniFile fl = us1.CreateUniFile("CUSTOMER");

                // read records as unidataset
                string[]   sArray = { "2", "12", "3", "4" };
                UniDataSet uSet   = fl.ReadRecords(sArray);

                // use for each statement to print the record
                foreach (UniRecord item in uSet)
                {
                    Console.WriteLine(item.ToString());
                }

                // use index to print the record
                int lCount = uSet.RowCount;
                for (int ii = 0; ii < lCount; ii++)
                {
                    UniRecord ee = uSet[ii];
                    Console.WriteLine(ee.ToString());
                }

                // print one by one record
                UniRecord q2  = uSet["2"];
                string    sq2 = q2.ToString();
                Console.WriteLine("  Record data for rec id 2:" + sq2);
                UniRecord q3  = uSet["3"];
                string    sq3 = q3.ToString();
                Console.WriteLine("  Record data for rec id 3:" + sq3);
                UniRecord q4  = uSet["4"];
                string    sq4 = q4.ToString();
                Console.WriteLine("  Record data for rec id 4:" + sq4);

                // create UniDataSet in the Client Side
                UniDataSet uSet3 = us1.CreateUniDataSet();
                uSet3.Insert("3", "aaa");
                uSet3.Insert("4", "bbb");
                uSet3.Insert("5", "vvv");
                uSet3.Insert(2, "8", "www");

                con.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Console.WriteLine("Enter to exit:");
                string line = Console.ReadLine();
            }
        }
예제 #5
0
        public bool Read()
        {
            if (_keySample == null)
            {
                return(false);
            }

            if ((_blockIdx > _keySample.Length) || (Limit > 0 && RecordsAffected >= Limit))
            {
                return(false);
            }

            if (0 == _rowIdx)
            {
                UniCommand uCmd = _uSession.CreateUniCommand();

                _keyBlock = null;
                while (_keyBlock == null)
                {
                    uCmd.Command = string.Format("SELECT {0} BY @ID", uFile.FileName);

                    if (_blockIdx > 0)
                    {
                        uCmd.Command += string.Format(" WITH @ID >= \"{0}\"",
                                                      _keySample[_blockIdx - 1].Replace("\"", "\"\""));
                    }


                    if (_blockIdx < _keySample.Length)
                    {
                        if (_blockIdx > 0)
                        {
                            uCmd.Command += " AND ";
                        }
                        else
                        {
                            uCmd.Command += " WITH ";
                        }

                        uCmd.Command += string.Format("@ID < \"{0}\"", _keySample[_blockIdx].Replace("\"", "\"\""));
                    }

                    uCmd.Execute();
                    usl       = _uSession.CreateUniSelectList(0);
                    _keyBlock = usl.ReadListAsStringArray();
                    if (_keyBlock == null)
                    {
                        _blockIdx++;
                    }
                }
                // Console.Write(_keyBlock.ToString());
                _uds = uFile.ReadRecords(_keyBlock);
            }

            if (_rowIdx < _keyBlock.Length)
            {
                _row.Clear();

                _row.Add(_keyBlock[_rowIdx]);
                _row.Add(_uds.GetRecord(_rowIdx).Record.ToString());

                _rowIdx++;
                if (_rowIdx == _keyBlock.Length)
                {
                    _rowIdx = 0;
                    _blockIdx++;
                }
            }

            RecordsAffected++;

            return(true);



            /*
             * try
             * {
             *
             * if (0 == i)
             * value = key;
             * else
             * {
             * var fld = udaRow.Extract(i).ToString();
             * if ("" != fld)
             * {
             * var xf = new XElement("fld" / *, new XAttribute("loc", i) * /);
             * for (var v = 1; v <= udaRow.Dcount(i); v++)
             * {
             * / *
             * XElement xv = new XElement("val", new XAttribute("loc", v));
             * string val = udaRow.Extract(i, v).ToString();
             * if ("" != val)
             * {
             * for (int s = 1; s <= udaRow.Dcount(i, v); s++)
             * {
             *  xv.Add(new XElement("sub", new XAttribute("loc", s), udaRow.Extract(i, v, s).ToString()));
             * }
             * }
             * xf.Add(xv);
             * /
             *
             * var val = udaRow.Extract(i, v).ToString();
             *
             *
             * //replace control characters that are invalid in xml with empty string
             * var re = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
             * val = Regex.Replace(val, re, "");
             *
             * // replace text and subtext remarks with carriage return
             * re = @"[\xFB\xFC]";
             * val = Regex.Replace(val, re, "\n");
             * //const string TM_CHAR = "\xFB";
             * //const string SM_CHAR = "\xFC";
             * //val.Replace(SM_CHAR, "\n");
             * //val.Replace(TM_CHAR, "\n");
             *
             * xf.Add(new XElement("val", new XAttribute("loc", v), val));
             * }
             * value = xf.ToString();
             * }
             * }
             * }
             * catch (Exception e)
             * {
             * Console.WriteLine(e.ToString());
             * }
             * if (null == value)
             * return DBNull.Value;
             * else
             * return value;
             *     */
        }