Ejemplo n.º 1
0
        //list all meters and gateways
        public void loadAll()
        {
            GateWayService gt          = new GateWayService(new List <TextBox>());
            List <Gateway> listGateWay = new List <Gateway>();

            listGateWay = gt.ListAllGateways();
            this.GridView_Gateways.DataSource = listGateWay;
            this.GridView_Gateways.DataBind();

            MeterService mt        = new MeterService(new List <TextBox>());
            List <Meter> listMeter = new List <Meter>();

            listMeter = mt.ListAllMeters();
            this.GridView_Meters.DataSource = listMeter;
            this.GridView_Meters.DataBind();
        }
Ejemplo n.º 2
0
        //to insert new meter and gateway
        protected void add_Click(object sender, EventArgs e)
        {
            if (this.options.SelectedItem.Text.Equals("Gateway") && !this.serialNumerBox.Text.Equals("") && !this.ipBox.Text.Equals(""))
            {
                List <TextBox> listText = new List <TextBox>();
                listText.Add(this.serialNumerBox);
                listText.Add(this.brandBox);
                listText.Add(this.modelBox);
                listText.Add(this.ipBox);
                listText.Add(this.portBox);

                GateWayService ms = new GateWayService(listText);
                if (!ms.CheckDuplicate())
                {
                    ms.RegisterGateWay();
                    cleanForm();
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showInfo", "alert('This gateway has been saved');", true);
                }
                else
                {
                    //alert alreay exists
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showError", "alert('This gateway already exists');", true);
                }
            }
            else if (!this.serialNumerBox.Text.Equals(""))
            {
                if (this.options.SelectedItem.Text.Equals("Light meter"))
                {
                    List <TextBox> listText = new List <TextBox>();
                    listText.Add(this.serialNumerBox);
                    listText.Add(this.brandBox);
                    listText.Add(this.modelBox);

                    MeterService ms = new MeterService(listText);
                    if (!ms.CheckDuplicate("Light-"))
                    {
                        ms.RegisterMeter("Light-");
                        cleanForm();
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showInfo", "alert('This meter has been saved');", true);
                    }
                    else
                    {
                        //alert alreay exists
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showError", "alert('This meter already exists');", true);
                    }
                }
                else if (this.options.SelectedItem.Text.Equals("Water meter"))
                {
                    List <TextBox> listText = new List <TextBox>();
                    listText.Add(this.serialNumerBox);
                    listText.Add(this.brandBox);
                    listText.Add(this.modelBox);

                    MeterService ms = new MeterService(listText);
                    if (!ms.CheckDuplicate("Water-"))
                    {
                        ms.RegisterMeter("Water-");
                        cleanForm();
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showInfo", "alert('This meter has been saved');", true);
                    }
                    else
                    {
                        //alert alreay exists
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showError", "alert('This meter already exists');", true);
                    }
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showError", "alert('Someone data has not been writtens');", true);
            }
        }