예제 #1
0
        /*Populate Grid function*/
        void Populate()
        {
            Debug.Print("Populating...");

            /*populating iniziale*/
            for (int i = 0; i < al.Count; i++)
            {
                Hashtable ht = al[i] as Hashtable;
                _dataGrid.AddItem(new DataGridItem(new object[4] {
                    ht["id"], ht["name"], ht["price"], qnt
                }));
            }
            _dataGrid.Invalidate();

            /*se l'utente deve modificare l'ordine'*/
            if (flagmdf == 1)
            {
                _pCounter.Text   = price.ToString();
                _qntCounter.Text = qnt.ToString();
                int qnt_appoggio = qnt;

                _dataGrid.Clear();
                _menu.Invalidate();
                _dataGrid.Invalidate();

                for (int i = 0; i < al.Count; i++)
                {
                    Hashtable ht = al[i] as Hashtable;
                    qnt = 0;
                    foreach (Product p in payment)
                    {
                        if (p.id == Double.Parse(ht["id"].ToString()))
                        {
                            qnt = p.quantita;
                        }
                    }
                    _dataGrid.AddItem(new DataGridItem(new object[4] {
                        ht["id"], ht["name"], ht["price"], qnt
                    }));
                }
                _dataGrid.Invalidate();
                qnt = qnt_appoggio;
            }
        }
예제 #2
0
        void Looping()
        {
            //create grid column
            dataGrid.AddColumn(new DataGridColumn("Room", 200));
            dataGrid.AddColumn(new DataGridColumn("Time", 200));
            dataGrid.AddColumn(new DataGridColumn("Light", 200));

            String[]  origin_names = null;
            ArrayList tabledata    = null;
            // Create a database in memory,
            // file system is possible however!
            Database myDatabase = new GHI.SQLite.Database();

            myDatabase.ExecuteNonQuery("CREATE Table Lights" +
                                       " (Room TEXT, Time TEXT, Value DOUBLE)");
            //reset database n display
            btnReset.TapEvent += (object sender) =>
            {
                myDatabase.ExecuteNonQuery("DELETE FROM Lights");
                dataGrid.Clear();
                dataGrid.Invalidate();
            };
            while (true)
            {
                //get sensor value
                var LightValue = lightSense.ReadProportion();
                var TimeStr    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var item       = new DataGridItem(new object[] { "My Room", TimeStr, LightValue });
                //add data to grid
                dataGrid.AddItem(item);
                dataGrid.Invalidate();
                //add rows to table
                myDatabase.ExecuteNonQuery("INSERT INTO Lights (Room, Time, Value)" +
                                           " VALUES ('My Room', '" + TimeStr + "' , " + LightValue + ")");

                // Process SQL query and save returned records in SQLiteDataTable
                ResultSet result = myDatabase.ExecuteQuery("SELECT * FROM Lights");
                // Get a copy of columns orign names example
                origin_names = result.ColumnNames;
                // Get a copy of table data example
                tabledata = result.Data;
                String fields = "Fields: ";
                for (int i = 0; i < result.ColumnCount; i++)
                {
                    fields += result.ColumnNames[i] + " |";
                }
                Debug.Print(fields);
                object obj;
                String row = "";
                for (int j = 0; j < result.RowCount; j++)
                {
                    row = j.ToString() + " ";
                    for (int i = 0; i < result.ColumnCount; i++)
                    {
                        obj = result[j, i];
                        if (obj == null)
                        {
                            row += "N/A";
                        }
                        else
                        {
                            row += obj.ToString();
                        }
                        row += " |";
                    }
                    Debug.Print(row);
                }

                Thread.Sleep(3000);
            }
            myDatabase.Dispose();
        }
예제 #3
0
        void PrintToLCD(string message)
        {
            String[]  origin_names = null;
            ArrayList tabledata    = null;

            //cek message
            if (message != null && message.Length > 0)
            {
                try
                {
                    if (message == "Radio Error")
                    {
                        return;
                    }
                    var        obj    = Json.NETMF.JsonSerializer.DeserializeString(message) as Hashtable;
                    var        detail = obj["Data"] as Hashtable;
                    DeviceData data   = new DeviceData()
                    {
                        DeviceSN = obj["DeviceSN"].ToString()
                    };
                    data.Data = new DataSensor()
                    {
                        Gas = Convert.ToDouble(detail["Gas"].ToString()), Temp = Convert.ToDouble(detail["Temp"].ToString()), Humid = Convert.ToDouble(detail["Humid"].ToString()), Light = Convert.ToDouble(detail["Light"].ToString())
                    };
                    //update display
                    txtTime.Text    = DateTime.Now.ToString("dd/MMM/yyyy HH:mm:ss");
                    txtMessage.Text = "Data Reveiced Successfully.";
                    txtTime.Invalidate();
                    txtMessage.Invalidate();

                    var TimeStr = DateTime.Now.ToString("dd/MM/yy HH:mm");
                    //insert to db
                    var item = new DataGridItem(new object[] { TimeStr, data.Data.Temp, data.Data.Humid, data.Data.Light, data.Data.Gas });
                    //add data to grid
                    GvData.AddItem(item);
                    Counter++;

                    GvData.Invalidate();
                    window.Invalidate();

                    //add rows to table
                    myDatabase.ExecuteNonQuery("INSERT INTO Sensor (Time, Temp,Humid,Light,Gas)" +
                                               " VALUES ('" + TimeStr + "' , " + data.Data.Temp + ", " + data.Data.Humid + ", " + data.Data.Light + ", " + data.Data.Gas + ")");
                    window.Invalidate();
                    if (Counter > 13)
                    {
                        //reset
                        Counter = 0;
                        myDatabase.ExecuteNonQuery("DELETE FROM Sensor");
                        GvData.Clear();
                        GvData.Invalidate();
                    }

                    /*
                     * // Process SQL query and save returned records in SQLiteDataTable
                     * ResultSet result = myDatabase.ExecuteQuery("SELECT * FROM Sensor");
                     * // Get a copy of columns orign names example
                     * origin_names = result.ColumnNames;
                     * // Get a copy of table data example
                     * tabledata = result.Data;
                     * String fields = "Fields: ";
                     * for (int i = 0; i < result.ColumnCount; i++)
                     * {
                     *  fields += result.ColumnNames[i] + " |";
                     * }
                     * Debug.Print(fields);
                     * object obj;
                     * String row = "";
                     * for (int j = 0; j < result.RowCount; j++)
                     * {
                     *  row = j.ToString() + " ";
                     *  for (int i = 0; i < result.ColumnCount; i++)
                     *  {
                     *      obj = result[j, i];
                     *      if (obj == null)
                     *          row += "N/A";
                     *      else
                     *          row += obj.ToString();
                     *      row += " |";
                     *  }
                     *  Debug.Print(row);
                     * }
                     */
                }
                catch (Exception ex)
                {
                    txtMessage.Text = message + "_" + ex.Message + "_" + ex.StackTrace;
                    txtMessage.Invalidate();
                }
            }
        }
예제 #4
0
        /*ordBtn TapEvent*/
        void _ordBtn_PressEvent(object sender)
        {
            var    random       = new Random(System.DateTime.Now.Millisecond);
            uint   randomNumber = (uint)random.Next();
            string id_ordine    = randomNumber.ToString();
            string tot          = price.ToString();


            Hashtable order = new Hashtable();

            order.Add("id", id_ordine);
            order.Add("price", tot);

            // Preparing order array list
            ArrayList foods = new ArrayList();

            foreach (Product p in payment)
            {
                // Preparing food array list
                Hashtable new_food = new Hashtable();
                new_food.Add("name", p.nome);
                new_food.Add("price", p.prezzo);


                Hashtable food = new Hashtable();
                food.Add("food", new_food);
                food.Add("quantity", p.quantita);

                foods.Add(food);
            }

            order.Add("foods", foods);

            string order_as_json = Json.NETMF.JsonSerializer.SerializeObject(order);

            // TODO: MANDARE order_as_json al Desktop tramite Socket
            Debug.Print(order_as_json);

            /*load ordina*/
            _ordina          = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Ordina));
            Glide.MainWindow = _ordina;
            _gridOrdine      = (GHI.Glide.UI.DataGrid)_menu.GetChildByName("gridOrdine");
            _annullaBtn      = (GHI.Glide.UI.Button)_ordina.GetChildByName("annullaBtn");
            _payBtn          = (GHI.Glide.UI.Button)_ordina.GetChildByName("payBtn");
            _mdfBtn          = (GHI.Glide.UI.Button)_ordina.GetChildByName("mdfBtn");
            _pfinal          = (GHI.Glide.UI.TextBlock)_ordina.GetChildByName("pFinal");

            _annullaBtn.TapEvent += _annullaBtn_TapEvent;
            _mdfBtn.TapEvent     += _mdfBtn_TapEvent;
            _payBtn.TapEvent     += _payBtn_TapEvent;

            /*Setup the dataGrid reference*/
            _gridOrdine = (DataGrid)_ordina.GetChildByName("gridOrdine");

            /*Create our four columns*/
            _gridOrdine.AddColumn(new DataGridColumn("PIZZA", 125));
            _gridOrdine.AddColumn(new DataGridColumn("PREZZO", 80));
            _gridOrdine.AddColumn(new DataGridColumn("QNT", 50));

            foreach (Product p in payment)
            {
                _gridOrdine.AddItem(new DataGridItem(new object[3] {
                    p.nome, p.prezzo, p.quantita
                }));
            }

            _pfinal.Text = price.ToString();

            _ordina.Invalidate();
            _gridOrdine.Invalidate();
        }