Exemple #1
0
        protected void paintDefinition()
        {
            // open the file from the definition
            if (Server.Instance.openFile(_defn.mainFile) == false)
            {
                throw new Exception("Cannot open file " + _defn.mainFile);
            }

            Text = _defn.heading;
            if (_defn.displayOnly)
            {
                cmdSave.Visible = false;
            }
            if (_defn.screenHeight > 0)
            {
                Height = _defn.screenHeight;
            }
            if (_defn.screenWidth > 0)
            {
                Width = _defn.screenWidth;
            }

            // build the display list
            ucScreen1.Screen = _defn;
            _fieldList       = Server.Instance.createArray();
            for (int i = 1; i <= _defn.fieldList.Count; i++)
            {
                _fieldList.Replace(i, _defn.fieldList[i - 1].name);
            }
        }
Exemple #2
0
        /// <summary>
        /// getScreenImage; get the display image for a screen data
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fieldList"></param>
        /// <param name="id"></param>
        /// <param name="record"></param>
        /// <param name="image"></param>
        /// <returns></returns>
        public Boolean getScreenImage(string fileName, string fieldList, string id, UniDynArray record, ref UniDynArray image)
        {
            try {
                lock (_syncCall) {
                    UniSubroutine s = _sess.CreateUniSubroutine("u2_getScreenImage", 6);
                    s.SetArg(0, fileName);
                    s.SetArg(1, fieldList);
                    s.SetArg(2, id);
                    s.SetArg(3, record);
                    s.SetArg(4, string.Empty);
                    s.SetArg(5, string.Empty);

                    s.Call();

                    String errtext = s.GetArg(5);
                    if (String.IsNullOrEmpty(errtext) == false)
                    {
                        ShowError(errtext);
                        return(false);
                    }
                    image = s.GetArgDynArray(4);
                }
            } catch (Exception ex) {
                ShowError(ex.Message);
                return(false);
            }
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// saveSalesOrder : save new or existing sales order
        /// </summary>
        /// <remarks>
        /// This calls a routine to save the order, to generate new order keys and to update relevant indices.
        /// </remarks>
        /// <param name="orderId"></param>
        /// <param name="orderRec"></param>
        /// <returns></returns>
        public Boolean saveSalesOrder(ref String orderId, ref UniDynArray orderRec)
        {
            String errText = String.Empty;

            try {
                lock (_syncCall) {
                    UniSubroutine s = _sess.CreateUniSubroutine("u2_saveSalesOrder", 3);
                    s.SetArg(0, orderId);
                    s.SetArg(1, orderRec);
                    s.Call();
                    orderId  = s.GetArg(0);
                    orderRec = s.GetArgDynArray(1);
                    errText  = s.GetArg(2);
                    if (String.IsNullOrEmpty(errText) == false)
                    {
                        ShowError(errText);
                        return(false);
                    }
                }
            } catch (Exception ex) {
                ShowError(ex.Message);
                return(false);
            }

            return(true);
        }
Exemple #4
0
 /// <summary>
 /// getShippingCosts: get the shipping descriptions and fixed costs
 /// </summary>
 /// <param name="shippingCosts"></param>
 /// <returns></returns>
 public Boolean getShippingCosts(ShippingCostList shippingCosts)
 {
     shippingCosts.Clear();
     try{
         lock (_syncCall) {
             UniSubroutine s      = _sess.CreateUniSubroutine("u2_getShippingRates", 3);
             String        inData = String.Empty;
             if (_moneyFormat == 1)
             {
                 inData = "1";
             }
             s.SetArg(0, inData);
             s.Call();
             UniDynArray da      = s.GetArgDynArray(1);
             int         noTaxes = da.Dcount(2);
             for (int i = 1; i <= noTaxes; i++)
             {
                 ShippingCost sc = new ShippingCost();
                 sc.ShippingId  = da.Extract(1, i).StringValue;
                 sc.Description = da.Extract(2, i).StringValue;
                 sc.Cost        = Utils.safeDouble(da.Extract(3, i).StringValue);
                 shippingCosts.Add(sc);
             }
         }
     } catch (Exception ex) {
         ShowError(ex.Message);
         return(false);
     }
     return(true);
 }
Exemple #5
0
        /// <summary>
        /// searchBooks: search for books (author, publisher or keyword)
        /// </summary>
        /// <remarks>
        /// This peforms a traditional search returning the results as a dynamic array.
        /// The results are parsed into a list of book summaries using regular extractions.
        /// </remarks>
        /// <param name="searchType"></param>
        /// <param name="searchData"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Boolean searchBooks(int searchType, String searchData, BookSummaryList list)
        {
            String      subrName = String.Empty;
            String      errText  = String.Empty;
            UniDynArray results  = null;

            list.Clear();

            switch (searchType)
            {
            case 0:     // author
                subrName = "u2_getBooksForAuthor";
                break;

            case 1:     // publisher
                subrName = "u2_getBooksForPublisher";
                break;

            case 2:
                subrName = "u2_getBooks";
                break;

            default:
                ShowError("Not a recognized search type");
                return(false);
            }

            searchData = searchData + FM_STR + moneyFormat.ToString();

            try {
                lock (_syncCall) {
                    UniSubroutine s = _sess.CreateUniSubroutine(subrName, 3);
                    s.SetArg(0, searchData);
                    s.Call();
                    errText = s.GetArg(2);
                    results = s.GetArgDynArray(1);

                    if (String.IsNullOrEmpty(results.StringValue) == false)
                    {
                        int dc = results.Dcount(BookConst.BOOKSUMMARY_BOOKID);
                        for (int i = 1; i <= dc; i++)
                        {
                            BookSummary b = new BookSummary();
                            b.BookId     = results.Extract(BookConst.BOOKSUMMARY_BOOKID, i).StringValue;
                            b.Title      = results.Extract(BookConst.BOOKSUMMARY_TITLE, i).StringValue;
                            b.AuthorName = results.Extract(BookConst.BOOKSUMMARY_AUTHORNAME, i).StringValue;
                            b.ISBN       = results.Extract(BookConst.BOOKSUMMARY_ISBN, i).StringValue;
                            b.SalesPrice = Convert.ToDouble(results.Extract(BookConst.BOOKSUMMARY_SALESPRICE, i).StringValue); // TBD
                            b.Media      = results.Extract(BookConst.BOOKSUMMARY_MEDIA, i).StringValue;
                            list.Add(b);
                        }
                    }
                }
            } catch (Exception ex) {
                ShowError(ex.Message);
                return(false);
            }
            return(true);
        }
Exemple #6
0
 private void ucScreen1_onDisplay(object sender, ref UniDynArray image)
 {
     if (String.IsNullOrEmpty(_defn.mainDict))
     {
         _defn.mainDict = _defn.mainFile;
     }
     Server.Instance.getScreenImage(_defn.mainDict, _fieldList.StringValue, ucScreen1.id, ucScreen1.rec, ref image);
 }
Exemple #7
0
        /// <summary>
        /// showOrderLines: show the order lines the hard way, going back to the server for additional data.
        /// </summary>
        protected void showOrderLines()
        {
            UniDynArray bookRec   = null;
            UniDynArray authorRec = null;

            double totalGoods = 0.0;
            double totalTax   = 0.0;

            int noLines = _orderRec.Dcount(BookConst.ORDERS_BOOK_ID);

            if (String.IsNullOrEmpty(_orderRec.Extract(BookConst.ORDERS_BOOK_ID).StringValue))
            {
                noLines = 0;
            }
            dgvLines.RowCount = noLines;
            for (int line = 1; line <= noLines; line++)
            {
                String bookId    = _orderRec.Extract(BookConst.ORDERS_BOOK_ID, line).StringValue;
                int    qty       = Utils.safeInt(_orderRec.Extract(BookConst.ORDERS_QTY, line).StringValue);
                double price     = Utils.safeDouble(_orderRec.Extract(BookConst.ORDERS_PRICE, line).StringValue) / 100;
                String taxCode   = _orderRec.Extract(BookConst.ORDERS_TAX_CODE, line).StringValue;
                String promotion = _orderRec.Extract(BookConst.ORDERS_PROMO_ID, line).StringValue;
                double taxrate   = Utils.safeDouble(_orderRec.Extract(BookConst.ORDERS_TAX_RATE, line).StringValue);

                // get the book and author details
                String authorName = "Unknown";
                if (Server.Instance.readRecord("U2_BOOKS", bookId, ref bookRec))
                {
                    if (Server.Instance.readRecord("U2_AUTHORS", bookRec.Extract(BookConst.BOOKS_AUTHOR_ID).StringValue, ref authorRec))
                    {
                        authorName = authorRec.Extract(BookConst.AUTHORS_FULLNAME).StringValue;
                    }
                }
                else
                {
                    bookRec = Server.Instance.createArray();
                }

                DataGridViewRow r = dgvLines.Rows[line - 1];

                r.Cells[COL_BOOK_ID].Value  = bookId;
                r.Cells[COL_TITLE].Value    = bookRec.Extract(BookConst.BOOKS_TITLE).StringValue;
                r.Cells[COL_AUTHOR].Value   = authorName;
                r.Cells[COL_QTY].Value      = qty;
                r.Cells[COL_PRICE].Value    = price;
                r.Cells[COL_TAX].Value      = taxCode;
                r.Cells[COL_GOODSAMT].Value = (price * qty);
                r.Cells[COL_TAXAMT].Value   = (price * qty * taxrate) / 100;
                r.Cells[COL_PROMO].Value    = promotion;

                totalGoods = totalGoods + (price * qty);
                totalTax   = totalTax + (price * qty * taxrate) / 100;
            }

            txtGoodCost.Text = String.Format("{0:N2}", totalGoods);
            txtTaxCost.Text  = String.Format("{0:N2}", totalTax);
            recalcTotals();
        }
Exemple #8
0
 /// <summary>
 /// createNewOrder: Set some standard defaults
 /// </summary>
 public void createNewOrder()
 {
     _orderId  = String.Empty;
     _orderRec = Server.Instance.createArray();
     _orderRec.Replace(BookConst.ORDERS_ORDER_STATUS, "NEW");
     _orderRec.Replace(BookConst.ORDERS_ORIGIN_CODE, "PHONE");
     _orderRec.Replace(BookConst.ORDERS_SHIP_ID, "FREE");
     showOrder();
     _changed = false;
 }
Exemple #9
0
        /// <summary>
        /// getClientData: get a full set of data for a single client
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="clientData"></param>
        /// <param name="errText"></param>
        /// <returns></returns>
        public Boolean getClientData(String clientId, ref ClientData clientData, ref String errText)
        {
            try {
                lock (_syncCall) {
                    UniSubroutine s = _sess.CreateUniSubroutine("u2_getClientData", 3);
                    s.SetArg(0, clientId);
                    s.Call();
                    if (String.IsNullOrEmpty(errText) == false)
                    {
                        ShowError(errText);
                        return(false);
                    }

                    UniDynArray da = s.GetArgDynArray(1);

                    clientData.ClientId = da.Extract(BookConst.CLIENTDATA_CLIENTID).StringValue;
                    clientData.Surname  = da.Extract(BookConst.CLIENTDATA_SURNAME).StringValue;
                    clientData.Forename = da.Extract(BookConst.CLIENTDATA_FORENAME).StringValue;
                    clientData.Address  = da.Extract(BookConst.CLIENTDATA_ADDRESS).StringValue.Replace(VM_STR, CRLF);
                    clientData.Country  = da.Extract(BookConst.CLIENTDATA_COUNTRY).StringValue;
                    clientData.JoinDate = da.Extract(BookConst.CLIENTDATA_JOINDATE).StringValue;

                    clientData.OrderList.Clear();
                    clientData.PaymentList.Clear();

                    int noOrders = da.Dcount(BookConst.CLIENTDATA_ORDERIDS);
                    for (int i = 1; i <= noOrders; i++)
                    {
                        ClientOrder co = new ClientOrder();
                        co.OrderId     = da.Extract(BookConst.CLIENTDATA_ORDERIDS, i).StringValue;
                        co.OrderStatus = da.Extract(BookConst.CLIENTDATA_ORDERSTATUS, i).StringValue;
                        co.OrderDate   = da.Extract(BookConst.CLIENTDATA_ORDERDATE, i).StringValue;
                        co.OrderTotal  = Utils.safeDouble(da.Extract(BookConst.CLIENTDATA_ORDERTOTAL, i).StringValue);
                        co.OrderTotal  = co.OrderTotal / 100;
                        clientData.OrderList.Add(co);
                    }
                    int noPayments = da.Dcount(BookConst.CLIENTDATA_PAYMENTIDS);
                    for (int i = 1; i <= noPayments; i++)
                    {
                        ClientPayment cp = new ClientPayment();
                        cp.PaymentId     = da.Extract(BookConst.CLIENTDATA_PAYMENTIDS, i).StringValue;
                        cp.PaymentDate   = da.Extract(BookConst.CLIENTDATA_PAYMENTDATE, i).StringValue;
                        cp.PaymentAmount = Utils.safeInt(da.Extract(BookConst.CLIENTDATA_PAYMENTAMT, i).StringValue);
                        cp.PaymentAmount = cp.PaymentAmount / 100;
                        clientData.PaymentList.Add(cp);
                    }
                }
            } catch (Exception ex) {
                ShowError(ex.Message);
                return(false);
            }
            return(true);
        }
Exemple #10
0
        private bool ucScreen1_onCheckRelation(object sender, string fileName, string key)
        {
            UniDynArray rec = Server.Instance.createArray();

            if (Server.Instance.openFile(fileName) == false)
            {
                return(false);
            }
            if (Server.Instance.readRecord(fileName, key, ref rec))
            {
                return(true);
            }
            return(false);
        }
Exemple #11
0
        /// <summary>
        /// setBookData; set the book data back to the server to be saved
        /// </summary>
        /// <param name="bookId"></param>
        /// <param name="data"></param>
        /// <param name="lockFlag"></param>
        /// <returns></returns>
        public Boolean setBookData(string bookId, BookData data, bool lockFlag)
        {
            UniDynArray da      = Server.Instance.createArray();
            String      errText = string.Empty;

            da.Replace(BookConst.BOOKDATA_AUTHOR_ID, data.AuthorId);
            da.Replace(BookConst.BOOKDATA_AUTHOR_NAME, data.AuthorName);
            da.Replace(BookConst.BOOKDATA_DEPT, data.Department);
            da.Replace(BookConst.BOOKDATA_GENRE, data.Genre);
            da.Replace(BookConst.BOOKDATA_ISBN, data.ISBN);
            da.Replace(BookConst.BOOKDATA_LONG_DESCRIPTION, data.LongDescription);
            da.Replace(BookConst.BOOKDATA_MEDIA, data.Media);
            da.Replace(BookConst.BOOKDATA_MIN_ORDER, data.MinOrderQty.ToString());
            da.Replace(BookConst.BOOKDATA_PUBLISHER_ID, data.PublisherId);
            da.Replace(BookConst.BOOKDATA_PUBLISHER_NAME, data.PublisherName);
            da.Replace(BookConst.BOOKDATA_PURCH_PRICE, (data.PurchasePrice * 100).ToString());
            da.Replace(BookConst.BOOKDATA_SALE_PRICE, (data.SalesPrice * 100).ToString());
            da.Replace(BookConst.BOOKDATA_STOCK_LEVEL, data.StockLevel.ToString());
            da.Replace(BookConst.BOOKDATA_SUPPLIER_ID, data.SupplierId);
            da.Replace(BookConst.BOOKDATA_SUPPLIER_NAME, data.SupplierName);
            da.Replace(BookConst.BOOKDATA_TAX_CODE, data.TaxCode);
            da.Replace(BookConst.BOOKDATA_TITLE, data.ShortTitle);

            try {
                lock (_syncCall) {
                    UniSubroutine s = _sess.CreateUniSubroutine("u2_setBookData", 4);
                    s.SetArg(0, bookId);
                    s.SetArg(1, da);
                    s.SetArg(2, "1");
                    s.SetArg(3, String.Empty);

                    s.Call();

                    errText = s.GetArg(3);
                }
                if (String.IsNullOrEmpty(errText) == false)
                {
                    ShowError(errText);
                    return(false);
                }
            } catch (Exception ex) {
                ShowError(ex.Message);
                return(false);
            }
            return(true);
        }
Exemple #12
0
        public static bool UpdateProducts(List <Orders> Cart, string OrderID, string Product)
        {
            try
            {
                int lRecID = 99;

                U2ConnectionStringBuilder conn_bldr = new U2ConnectionStringBuilder();
                conn_bldr.UserID         = "administrator";
                conn_bldr.Password       = "******";
                conn_bldr.Server         = "myserver";
                conn_bldr.ServerType     = "universe";
                conn_bldr.Database       = "HS.SALES";
                conn_bldr.AccessMode     = "Native";
                conn_bldr.RpcServiceType = "uvcs";
                string       lConnStr = conn_bldr.ConnectionString;
                U2Connection lConn    = new U2Connection();
                lConn.ConnectionString = lConnStr;
                lConn.Open();
                UniSession lUniSession = lConn.UniSession;
                U2Command  cmd         = lConn.CreateCommand();

                //CUSTID,FNAME,LNAME : Single Value
                //PRODID, BUY_DATE    : Multi Value
                //Syntax : Action=Update;File=?;Attributes=?;Where=?;Sort


                UniDynArray lArr = new UniDynArray(lUniSession, "2/1/1991");
                lArr.Insert(1, -1, "3/9/1991");
                lArr.Insert(1, -1, "4/1/1991");

                string lCmd = string.Format("UPDATE SHOPPINGCART SET FNAME={0},BUY_DATE='{1}'  WHERE CUSTID={2} ", "Fred2", lArr.StringValue, lRecID);
                cmd.CommandText = lCmd;
                int l2 = cmd.ExecuteNonQuery();

                lConn.Close();
            }
            catch (Exception e2)
            {
                string lErr = e2.Message;
                if (e2.InnerException != null)
                {
                    lErr += lErr + e2.InnerException.Message;
                }
            }
            return(true);
        }
Exemple #13
0
        /// <summary>
        /// getBookData: get full set of extended data for a book
        /// </summary>
        /// <!--
        /// Note that prices are held as whole pence/cents. These are descaled locally to ensure they
        /// fit the locale of the PC.
        /// -->
        /// <param name="bookId"></param>
        /// <param name="withLock"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public Boolean getBookData(String bookId, Boolean withLock, BookData data)
        {
            try {
                lock (_syncCall) {
                    UniSubroutine s = _sess.CreateUniSubroutine("u2_getBookData", 4);
                    s.SetArg(0, bookId);
                    s.SetArg(1, withLock ? "1" : "0");
                    s.Call();
                    String errText = s.GetArg(3);
                    if (String.IsNullOrEmpty(errText) == false)
                    {
                        ShowError(errText);
                        return(false);
                    }
                    UniDynArray da = s.GetArgDynArray(2);

                    data.BookId          = bookId;
                    data.ShortTitle      = da.Extract(BookConst.BOOKDATA_TITLE).StringValue;
                    data.AuthorId        = da.Extract(BookConst.BOOKDATA_AUTHOR_ID).StringValue;
                    data.AuthorName      = da.Extract(BookConst.BOOKDATA_AUTHOR_NAME).StringValue;
                    data.ISBN            = da.Extract(BookConst.BOOKDATA_ISBN).StringValue;
                    data.Department      = da.Extract(BookConst.BOOKDATA_DEPT).StringValue;
                    data.Genre           = da.Extract(BookConst.BOOKDATA_GENRE).StringValue;
                    data.Media           = da.Extract(BookConst.BOOKDATA_MEDIA).StringValue;
                    data.PublisherId     = da.Extract(BookConst.BOOKDATA_PUBLISHER_ID).StringValue;
                    data.PublisherName   = da.Extract(BookConst.BOOKDATA_PUBLISHER_NAME).StringValue;
                    data.SalesPrice      = Utils.safeInt(da.Extract(BookConst.BOOKDATA_SALE_PRICE).StringValue);
                    data.SalesPrice      = data.SalesPrice / 100; //note held as whole pence/cents.
                    data.StockLevel      = Utils.safeInt(da.Extract(BookConst.BOOKDATA_STOCK_LEVEL).StringValue);
                    data.MinOrderQty     = Utils.safeInt(da.Extract(BookConst.BOOKDATA_MIN_ORDER).StringValue);
                    data.TaxCode         = da.Extract(BookConst.BOOKDATA_TAX_CODE).StringValue;
                    data.SupplierId      = da.Extract(BookConst.BOOKDATA_SUPPLIER_ID).StringValue;
                    data.SupplierName    = da.Extract(BookConst.BOOKDATA_SUPPLIER_NAME).StringValue;
                    data.PurchasePrice   = Utils.safeInt(da.Extract(BookConst.BOOKDATA_PURCH_PRICE).StringValue);
                    data.PurchasePrice   = data.PurchasePrice / 100;
                    data.LongDescription = da.Extract(BookConst.BOOKDATA_LONG_DESCRIPTION).StringValue.Replace(VM_STR, CRLF);
                }
            } catch (Exception ex) {
                ShowError(ex.Message);
                return(false);
            }
            return(true);
        }
Exemple #14
0
        public Boolean writeRecord(String fileName, String id, UniDynArray rec)
        {
            _lastError = String.Empty;
            UniFile f = getFile(fileName);

            if (f == null)
            {
                return(false);
            }
            lock (_syncCall) {
                try {
                    f.Write(id, rec.StringValue);
                } catch (Exception ex) {
                    _lastError = ex.Message;
                    return(false);
                }
            }
            return(true);
        }
Exemple #15
0
        public Boolean readRecord(String fileName, String id, ref UniDynArray rec)
        {
            _lastError = String.Empty;
            UniFile f = getFile(fileName);

            if (f == null)
            {
                return(false);
            }
            lock (_syncCall) {
                try {
                    rec = f.Read(id);
                } catch (Exception ex) {
                    _lastError = ex.Message;
                    return(false);
                }
            }
            return(true);
        }
Exemple #16
0
 /// <summary>
 /// readParameter: read a parameter record from the U2_PARAMS file.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public Boolean readParameter(String id, ref String result)
 {
     if (openFile("U2_PARAMS") == false)
     {
         ShowError("Cannot open parameter file");
         return(false);
     }
     lock (_syncCall) {
         UniDynArray rec = null;
         if (readRecord("U2_PARAMS", id, ref rec) == false)
         {
             result = String.Empty;
         }
         else
         {
             result = rec.StringValue;
         }
     }
     return(true);
 }
Exemple #17
0
        /// <summary>
        /// getClient : get and display the details for the order client.
        /// </summary>
        /// <param name="clientId"></param>
        protected void getClient(string clientId)
        {
            // read client name
            UniDynArray clientRec = null;

            if (String.IsNullOrEmpty(clientId))
            {
                clientRec = Server.Instance.createArray();
            }
            else
            {
                Server.Instance.readRecord("U2_CLIENTS", clientId, ref clientRec);
            }

            lblClientName.Text = clientRec.Extract(BookConst.CLIENTS_FORENAME).StringValue + " " + clientRec.Extract(BookConst.CLIENTS_SURNAME).StringValue;
            lblAddress.Text    = clientRec.Extract(BookConst.CLIENTS_ADDRESS).StringValue.Replace(Server.VM_STR, Server.CRLF);

            // Check client is not on hold
            if (Utils.safeBool(clientRec.Extract(BookConst.CLIENTS_ACCOUNT_HELD).StringValue))
            {
                Server.Instance.ShowError("Client account is on hold");
            }
        }
Exemple #18
0
 /// <summary>
 /// getSalesTaxes: get a list of sales taxes
 /// </summary>
 /// <param name="salesTaxDict"></param>
 /// <returns></returns>
 public Boolean getSalesTaxes(SalesTaxDict salesTaxDict)
 {
     try {
         salesTaxDict.Clear();
         lock (_syncCall) {
             UniSubroutine s = _sess.CreateUniSubroutine("u2_getSalesTaxes", 2);
             s.Call();
             UniDynArray da      = s.GetArgDynArray(0);
             int         noTaxes = da.Dcount(1);
             for (int i = 1; i <= noTaxes; i++)
             {
                 SalesTax st = new SalesTax();
                 st.TaxCode          = da.Extract(1, i).StringValue;
                 st.ShortDescription = da.Extract(2, i).StringValue;
                 st.Rate             = Convert.ToDouble(da.Extract(3, i).StringValue);
                 salesTaxDict.Add(st.TaxCode, st);
             }
         }
     } catch (Exception ex) {
         ShowError(ex.Message);
         return(false);
     }
     return(true);
 }
Exemple #19
0
        protected bool callFieldEvent(string subrName, string fieldName, string eventName, ref UniDynArray outData, ref UniDynArray actions)
        {
            try {
                List <String> args = new List <String>();
                args.Add(fieldName);
                args.Add(eventName);
                args.Add(ucScreen1.id);
                args.Add(ucScreen1.rec.StringValue);
                args.Add(outData.StringValue);
                args.Add(string.Empty);
                Server.Instance.callSub(subrName, args);

                outData = new UniDynArray(Server.Instance.Session, args[4]);
                actions = new UniDynArray(Server.Instance.Session, args[5]);
                if (args[3] != ucScreen1.rec.StringValue)
                {
                    ucScreen1.setRecord(new UniDynArray(Server.Instance.Session, args[3]));
                }
            }
            catch (Exception ex) {
                return(false);
            }
            return(true);
        }
Exemple #20
0
        /// <summary>
        /// dosave: this does the build and save directly from the client.
        /// </summary>
        /// <remarks>
        /// This should only be used for single file or simple updates.
        /// </remarks>
        protected void doSave()
        {
            // read and update the current record
            UniDynArray clientRec = null;

            if (Server.Instance.readRecord("U2_CLIENTS", _clientData.ClientId, ref clientRec) == false)
            {
                clientRec = Server.Instance.createArray();
            }
            clientRec.Replace(BookConst.CLIENTS_FORENAME, txtForename.Text);
            clientRec.Replace(BookConst.CLIENTS_SURNAME, txtSurname.Text);
            String iDate = String.Empty;

            if (Server.Instance.iconv(txtJoinDate.Text, "D", ref iDate))
            {
                clientRec.Replace(BookConst.CLIENTS_JOIN_DATE, iDate);
            }
            clientRec.Replace(BookConst.CLIENTS_ADDRESS, txtAddress.Text.Replace(Server.CRLF, Server.VM_STR));

            if (Server.Instance.writeRecord("U2_CLIENTS", _clientId, clientRec))
            {
                MessageBox.Show("Client details updated");
            }
        }
Exemple #21
0
        public static bool InsertOrderItem(List <Orders> LineItem, string OrderNumber)
        {
            try
            {
                U2ConnectionStringBuilder conn_bldr = new U2ConnectionStringBuilder();
                conn_bldr.UserID         = "Demo";
                conn_bldr.Password       = "******";
                conn_bldr.Server         = "localhost";
                conn_bldr.ServerType     = "universe";
                conn_bldr.Database       = "pwdemo";
                conn_bldr.AccessMode     = "Native";
                conn_bldr.RpcServiceType = "uvcs";



                string       lConnStr = conn_bldr.ConnectionString;
                U2Connection lConn    = new U2Connection();
                lConn.ConnectionString = lConnStr;
                lConn.Open();
                UniSession lUniSession = lConn.UniSession;
                U2Command  cmd         = lConn.CreateCommand();

                //Unique sale ID or invoice Number. Do we add userid as well?
                // We will work with the assumption that it's one order - 5001
                int newrecid = Convert.ToInt32(OrderNumber);


                UniDynArray Product  = new UniDynArray(lUniSession);
                UniDynArray Quantity = new UniDynArray(lUniSession);
                UniDynArray Sale     = new UniDynArray(lUniSession);



                foreach (var order in LineItem)
                {
                    string ProdID = order.Serial.ToString();
                    string Quan   = order.Quantity.ToString();
                    string price  = order.Cost.ToString();

                    Product.Insert(1, -1, ProdID);
                    Quantity.Insert(1, -1, Quan);
                    Sale.Insert(1, -1, price);
                }


                string lCmd = string.Format("INSERT INTO SHOPPINGCART (RECID,PROD,QUAN,SALE) VALUES('{0}','{1}','{2}','{3}')", newrecid, Product, Quantity, Sale);

                cmd.CommandText = lCmd;
                int l2 = cmd.ExecuteNonQuery();

                lConn.Close();
            }
            catch (Exception e2)
            {
                string lErr = e2.Message;
                if (e2.InnerException != null)
                {
                    lErr += lErr + e2.InnerException.Message;
                }
                return(false);
            }

            return(true);
        }
Exemple #22
0
 private bool ucScreen1_onRead(object sender, string fileName, string key, bool locking, ref bool isNew, ref UniDynArray rec)
 {
     isNew = false;
     if (locking)
     {
         if (Server.Instance.lockRecord(fileName, key) == false)
         {
             if (Server.Instance.lastErrorCode != "30001")
             {
                 MessageBox.Show("Cannot get record lock on " + key);
                 return(false);
             }
         }
     }
     if (Server.Instance.readRecord(fileName, key, ref rec) == false)
     {
         if (Server.Instance.lastErrorCode != "30001")
         {
             MessageBox.Show("Error reading record " + key);
             return(false);
         }
         else
         {
             isNew = true;
             rec   = Server.Instance.createArray();
         }
     }
     return(true);
 }
Exemple #23
0
 private bool ucScreen1_FieldOnEntryEvent(object sender, string subrName, FieldDefn f, ref UniDynArray outData, ref UniDynArray actions)
 {
     return(callFieldEvent(subrName, f.name, "ONENTRY", ref outData, ref actions));
 }
Exemple #24
0
        //public static bool InsertOrderItem(Orders LineItem, string OrderNumber)
        //{

        //    string s = ConfigurationManager.AppSettings["TESTString"];
        //    U2Connection con = new U2Connection();
        //    con.ConnectionString = s;
        //    con.Open();

        //    UniSession LUniSession = con.UniSession;
        //    U2Command cmd = con.CreateCommand();

        //    int recID = 9999;
        //    int Prod = 1234;
        //    int quantity = 1;
        //    double cost = 9.99;



        //    //Insert
        //    string lcmd = string.Format("INSERT INTO SHOPPINGCART RECID,PROD,QUAN,COST) VALUES('{0}','{1}','{2}','{3}')", recID, Prod, quantity, cost);
        //    cmd.CommandText = lcmd;

        //    try { int L2 = cmd.ExecuteNonQuery(); }
        //    catch(Exception ex) { return false; }
        //    finally { }

        //    return true;


        //}

        public static bool InsertOrderItem(List <Orders> LineItem, string OrderNumber)
        {
            try
            {
                U2ConnectionStringBuilder conn_bldr = new U2ConnectionStringBuilder();
                conn_bldr.UserID         = "Demo";
                conn_bldr.Password       = "******";
                conn_bldr.Server         = "localhost";
                conn_bldr.ServerType     = "universe";
                conn_bldr.Database       = "pwdemo";
                conn_bldr.AccessMode     = "Native";
                conn_bldr.RpcServiceType = "uvcs";



                string       lConnStr = conn_bldr.ConnectionString;
                U2Connection lConn    = new U2Connection();
                lConn.ConnectionString = lConnStr;
                lConn.Open();
                UniSession lUniSession = lConn.UniSession;
                U2Command  cmd         = lConn.CreateCommand();

                //Unique sale ID or invoice Number. Do we add userid as well?
                // We will work with the assumption that it's one order - 5001
                int newrecid = 5001;


                UniDynArray Product  = new UniDynArray(lUniSession);
                UniDynArray Quantity = new UniDynArray(lUniSession);
                UniDynArray Sale     = new UniDynArray(lUniSession);



                foreach (var order in LineItem)
                {
                    string ProdID = order.Serial.ToString();
                    string Quan   = order.Quantity.ToString();
                    string price  = order.Cost.ToString();

                    Product.Insert(1, -1, ProdID);
                    Quantity.Insert(1, -1, Quan);
                    Sale.Insert(1, -1, price);
                }

                // As we add reccords, we will need to read , loop and drop into UniDynArray.
                // For now, just enter line item.



                //Sale.Insert(1, -1, price2);
                //Sale.Insert(1, -1, price3);


                string lCmd = string.Format("INSERT INTO SHOPPINGCART (RECID,PROD,QUAN,SALE) VALUES('{0}','{1}','{2}','{3}')", newrecid, Product, Quantity, Sale);
                //string lCmd = string.Format("INSERT INTO SHOPPINGCART VALUES (newrecid, Product, Quantity, Sale)");
                //string lCmd = string.Format("INSERT INTO SHOPPINGCART (PROD,QUAN,SALE) VALUES('{0}','{1}','{2}')", Product, Quantity, Sale);



                cmd.CommandText = lCmd;
                int l2 = cmd.ExecuteNonQuery();


                //print inserted value
                //cmd.CommandText = string.Format("Action=Select;File=SHOPPINGCART;Attributes=RECID,PROD,QUAN,SALE;Where=RECID={0}", newrecid);
                //U2DataAdapter da = new U2DataAdapter(cmd);
                //DataSet ds = new DataSet();
                //da.Fill(ds);

                // delete inserted value
                //Console.WriteLine(Environment.NewLine + "Start : Delete new inserted value...............");
                //cmd.CommandText = string.Format("Action=Delete;File=SHOPPINGCART;Where=RECID={0}", newrecid);
                //l2 = cmd.ExecuteNonQuery();


                //close connection
                lConn.Close();
            }
            catch (Exception e2)
            {
                string lErr = e2.Message;
                if (e2.InnerException != null)
                {
                    lErr += lErr + e2.InnerException.Message;
                }
                return(false);
            }

            return(true);
        }
Exemple #25
0
        static void Main(string[] args)
        {
            bool debug = Properties.Settings.Default.Verbose;
            
            U2Conn srcConn = new U2Conn();
            SqlConn destConn = new SqlConn();
            
            srcConn.Host = Properties.Settings.Default.U2Host; // "pmsteel.kwyk.net";
            srcConn.Login = Properties.Settings.Default.U2Login; // "administrator";
            srcConn.Password = Properties.Settings.Default.U2Password; // "H!carb0n";
            srcConn.Catalog = Properties.Settings.Default.U2Account; // "C:\\BAI.PROD\\PM";

            destConn.Host = Properties.Settings.Default.SqlHost; // "pmsteel.kwyk.net";
            destConn.Login = Properties.Settings.Default.SqlLogin; // "pmsteel";
            destConn.Password = Properties.Settings.Default.SqlPassword; // "H!carb0n";
            destConn.Catalog = Properties.Settings.Default.SqlDatabase; // "pmsteel"

            /*
            try
            {
                srcConn.Connect();
                destConn.Connect();
                srcConn.Disconnect();
                destConn.Disconnect();
            }
            catch (Exception e)
            {
                debugPrint(true, "Error: " + e);
            }
            */

            String sqlStmt = "";
            
            try
            {
                // every thing runs out of the UniSession instance.
                UniSession uSession = null;

                //Set up variables.
                uSession = UniObjects.OpenSession(Properties.Settings.Default.U2Host, Properties.Settings.Default.U2Login, 
                                                  Properties.Settings.Default.U2Password, Properties.Settings.Default.U2Account);
                
                debugPrint(debug, "U2 openSession succeeded\n");

                debugPrint(debug, "Status = " + uSession.Status + "\n");

                //Class.forName("net.sourceforge.jtds.jdbc.Driver");
                //Connection conn = DriverManager.getConnection(sqlJdbcUrl, sqlUser, sqlPass);
                //debugPrint(debug, "SQL Server connection succeeded");
                //Statement stmt = conn.createStatement();

                UniFile uf = uSession.CreateUniFile(Properties.Settings.Default.U2File);
                debugPrint(debug, Properties.Settings.Default.U2File + " file opened\n");
                //debugPrint(debug, uf.ToString());

                UniSelectList usl = uSession.CreateUniSelectList(8);

                StreamWriter sw = new StreamWriter(@"c:\temp\u2rl.xml");
                        
                usl.Select(uf);
                while (!usl.LastRecordRead)
                {
                    String key = usl.Next();
                    debugPrint(debug, "key: " + key + "\n");
                    if (key != "")
                    {
                        XElement xd = new XElement("data");
                        XElement xd2 = new XElement("data");
                        UniDynArray udaRow = uf.Read(key);
                        int v2 = 0;
                        int s2 = 1;
                        while (s2 > 0)
                        {
                            XElement xv2 = new XElement("val", new XAttribute("loc", s2));
                            s2 = 0;
                            for (int f2 = 1; f2 <= udaRow.Dcount(); f2++)
                            {
                                if ( s2 <= udaRow.Dcount(f, v))
                                {
                                XElement xf2 = new XElement("fld", new XAttribute("loc", f2));
                                string fld = udaRow.Extract(f2, v2).ToString();
                                if ("" != fld)
                                {
                                }
                            }
                        }
                        for (int f = 1; f <= udaRow.Dcount(); f++)
                        {
                            XElement xf = new XElement("fld", new XAttribute("loc", f));
                            string fld = udaRow.Extract(f).ToString();
                            if ("" != fld)
                            {
                                for (int v = 1; v <= udaRow.Dcount(f); v++)
                                {
                                    XElement xv = new XElement("val", new XAttribute("loc", v));
                                    string val = udaRow.Extract(f, v).ToString();
                                    if ("" != val)
                                    {
                                        for (int s = 1; s <= udaRow.Dcount(f, v); s++)
                                        {
                                            xv.Add(new XElement("sub", new XAttribute("loc", s), udaRow.Extract(f, v, s).ToString()));
                                        }
                                    }
                                    xf.Add(xv);
                                }
                            }
                            xd.Add(xf);
                        }
                        XElement xr = new XElement("row", new XElement("id", key), xd);
                        sqlStmt = "INSERT INVF(u2_id, u2_data) VALUES ('" + key.Replace("'", "''") + "', '" + xd.ToString().Replace("'", "''") + "')";
                        sw.WriteLine(xr);
                    }
                }
                sw.Close();

                //UniDynArray udaRow = uSession.CreateUniDynArray(usl.Next());
                //debugPrint(debug, usl.readList().ToString());
                //while (!usl.IsLastRecordRead)
                //while (null != udaRow)
                //{
                    //String usKey = udaRow.Extract(1).ToString();
                    //Properties.Settings.Default.SqlTable = usKey;
                    //debugPrint(debug, "key: " + usKey + "\n");
                    //debugPrint(debug, usKey.ToString() + ": " + Properties.Settings.Default.SqlTable);
                    //sqlStmt = "IF EXISTS (SELECT * FROM sys.tables WHERE OBJECT_ID('dbo.[" + Properties.Settings.Default.SqlTable + "]') IS NOT NULL) DROP TABLE dbo.[" + Properties.Settings.Default.SqlTable + "]";
                    //debugPrint(debug, sqlStmt);
                    //stmt.executeUpdate(sqlStmt);
                    //sqlStmt = "CREATE TABLE dbo.[" + Properties.Settings.Default.SqlTable + "] (ID varchar(255) NOT NULL,LOC smallint NOT NULL,SEQ smallint NOT NULL,VAL varchar(8000) NOT NULL)";
                    //debugPrint(debug, sqlStmt);
                    //stmt.executeUpdate(sqlStmt);

                    //{{ int valIdx = 1; int fldIdx = 1;
                    //for (int fldIdx = 1; fldIdx <= udaRow.Dcount(); fldIdx++)
                    //{
                    //    debugPrint(debug, "field: " + udaRow.Extract(fldIdx).ToString());
                    //    for (int valIdx = 1; valIdx <= udaRow.dcount(fldIdx); valIdx++)
                    //    {
                    //        UniString usValue = udaRow.extract(fldIdx, valIdx);
                    //        debugPrint(debug, usValue.ToString());
                    //    }
                    //}

                    //UniFile ufTblFile = uSession.open(usKey);
                    //debugPrint(debug, "file opened");
                    ////debugPrint(debug, usKey.ToString());

                    //UniSelectList uslTblList = uSession.selectList(2);

                    //uslTblList.select(ufTblFile);
                    //UniString usTblKey = uslTblList.next();
                    //int cnt = 0;

                    //while (!uslTblList.isLastRecordRead())
                    //{

                    //    if (cnt++ % 1000 == 0) debugPrint(debug, "rows: " + cnt);
                    //    //debugPrint(debug, usTblKey.ToString());
                    //    UniDynArray udaTblRow = new UniDynArray(ufTblFile.read(usTblKey));

                    //    for (int fldTblIdx = 1; fldTblIdx <= udaTblRow.dcount(); fldTblIdx++)
                    //    {
                    //        for (int valTblIdx = 1; valTblIdx <= udaTblRow.dcount(fldTblIdx); valTblIdx++)
                    //        {
                    //            UniString usTblValue = udaTblRow.extract(fldTblIdx, valTblIdx);
                    //            //debugPrint(debug, usTblValue.ToString());
                    //            sqlStmt = "INSERT [" + Properties.Settings.Default.SqlTable + "] VALUES ('" + usTblKey.ToString().replace("'", "''") + "', " + fldTblIdx + ", " + valTblIdx + ", '" + usTblValue.ToString().replace("'", "''") + "')";

                    //            //debugPrint(debug, sqlStmt);
                    //            //stmt.executeUpdate(sqlStmt);

                    //        }
                    //    }
                    //    usTblKey = uslTblList.next();
                    //}

                    //udaRow = uSession.CreateUniDynArray(usl.Next());
                //}
                /*
                udaKeys = usl.readList();
                //UniDynArray udaValues;
 
                sqlStmt = "TRUNCATE TABLE [" + Properties.Settings.Default.SqlTable + ']';
                debugPrint(debug, sqlStmt);
                stmt.executeUpdate(sqlStmt);
    	 

                for (int keyIdx = 1;keyIdx < udaKeys.count();keyIdx++) {
                    usKey = udaKeys.extract(keyIdx);
                    debugPrint(debug, usKey.ToString());
                    if (usKey.length() > 0) {
                        debugPrint(debug, udaKeys.count() + " " + usKey + usKey.length() + " " + keyIdx);
                        sqlStmt = "INSERT [" + Properties.Settings.Default.SqlTable + "] VALUES ('" + usKey + "', 0, 1, '" +  usKey + "')";
                        debugPrint(debug, sqlStmt);
                        stmt.executeUpdate(sqlStmt);
                        udaRow = new UniDynArray(uf.read(usKey));
                        for (int fldIdx = 1; fldIdx <= udaRow.dcount(); fldIdx++) {
                            //usField = udaRow.extract(fldIdx) ;
                            //udaValues = new UniDynArray(usField);
                            for (int valIdx = 1; valIdx <= udaRow.dcount(fldIdx); valIdx++) {
                                usValue = udaRow.extract(fldIdx, valIdx) ;
                                if (usValue.length() > 0) {
                                    //debugPrint(debug, fldIdx + " " + valIdx + " -->" + usValue + "<--");
		        		 
                                    sqlStmt = "INSERT [" + Properties.Settings.Default.SqlTable+ "] VALUES ('" + usKey + "', " + fldIdx + ", " + valIdx + ", '" +  usValue.ToString().replace("'", "''") + "')";
                                    debugPrint(debug, sqlStmt);
                                    stmt.executeUpdate(sqlStmt);
                                }
                            }
                        }
                    }
                    //debugPrint(debug, udaKeys.extract(keyIdx));
                }
                */
                uf.Close();
                debugPrint(debug, Properties.Settings.Default.U2File + " file closed\n");
                
                // did we connect?

                debugPrint(debug, "U2 Disconnected\n");
                //conn.close();
                //debugPrint(debug, "SQL Disconnected.");

            }
            catch (UniSessionException e)
            {
                debugPrint(debug, "Error: " + e);
            }
            catch (UniFileException e)
            {
                debugPrint(debug, "File Error: " + e);
            }
            catch (UniSelectListException e)
            {
                // TODO Auto-generated catch block
                debugPrint(debug, "File Error: " + e);
            }
            Console.ReadKey();
        }
Exemple #26
0
 private bool ucScreen1_onWrite(object sender, string fileName, string key, UniDynArray rec)
 {
     return(Server.Instance.writeRecord(fileName, key, rec));
 }