示例#1
0
 /*
   Funcion: Inserta un nuevo equipo
   Param: Id, GroupId,BrandId,Model,HMIAddress,PLCLink,PLCAddress,Location,Status
   Return: Status
   */
 public String insertEquipment(EquipmentInsertView equipment)
 {
     return context.InsertUpdateDeleteMSQL("EXEC createEquipment @EquipmentId='"+equipment.Id+"', @EquipmentGroupId="+equipment.GroupId
         + ", @EquipmentBrandId="+equipment.BrandId
         +", @EquipmentModel='"+equipment.Model+"', @EquipmentHMIAddress='"+equipment.HMIAddress+"', @EquipmentPLCLink="+
         equipment.PLCLink+", @EquipmentPLCAddress='"+equipment.PLCAddress+"', @EquipmentLocation='"+equipment.Location
             + "', @EquipmentStatus=" + equipment.Status+ ";");
 }
        /*
        Metodo que se utiliza para guardar un nuevo equipo
        */
        private void saveAuxiliar()
        {
            //Se verifica que se haya completado el grupo y el brand
            if (EquipmentGroupText.SelectedItem != null & BrandText.SelectedItem != null)
            {
                //Se verifica que los demas campos esten completos
                if (EquipmentGroupText.SelectedItem.Value != "" & BrandText.SelectedItem.Value != ""
                    & HMIAddressText.Text != "" & EquipmentIdText.Text != "" &
                    LocationText.Text != "" & ModelText.Text != "" & PLCAddressText.Text != "")
                {
                    //Se crea el servicio
                    EquipmentService equipmentService = new EquipmentService();
                    EquipmentInsertView insertView = new EquipmentInsertView();
                    //Se llenan los datos
                    insertView.BrandId = Int32.Parse(BrandText.SelectedItem.Value);
                    insertView.GroupId = Int32.Parse(EquipmentGroupText.SelectedItem.Value);
                    insertView.HMIAddress = HMIAddressText.Text;
                    insertView.Id = EquipmentIdText.Text;
                    insertView.Location = LocationText.Text;
                    insertView.Model = ModelText.Text;
                    insertView.PLCAddress = PLCAddressText.Text;
                    insertView.PLCLink = ethernetLink.Items[0].Selected;
                    insertView.Status = EquipmentEnable.Items[0].Selected;
                    //Se llenan los datos para la auditoria
                    String user = Context.User.Identity.Name;
                    AuditDataFromWeb audit = new AuditDataFromWeb();
                    audit.Reason = "N/A";
                    audit.StationIP = General.getIp(this.Page);
                    audit.UserName = user;
                    //Se realiza la insercion
                    CUDView crud = equipmentService.insertEquipment(insertView, audit);

                    if (crud.insert == false)
                    {
                        if (crud.errorMessage == "errHMIPLC")
                        {
                            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('The IP address of the PLC or HMI is already assigned.')", true);
                        }
                        else
                        {
                            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the Equipment')", true);
                        }
                    }
                    else
                    {
                        clearFields1();
                        fillEquipmentTable();
                    }

                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields.')", true);
                }

            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields.')", true);
            }
        }
        private void saveAuxiliar()
        {
            if (EquipmentGroupText.SelectedItem != null & BrandText.SelectedItem != null)
            {
                if (EquipmentGroupText.SelectedItem.Value != "" & BrandText.SelectedItem.Value != "" &
                    EquipmentSubIdText.Text != "" & HMIAddressText.Text != "" & EquipmentIdText.Text != "" &
                    LocationText.Text != "" & ModelText.Text != "" & PLCAddressText.Text != ""){

                    int n;
                    bool isNumeric = int.TryParse(EquipmentSubIdText.Text, out n);

                    if (isNumeric)
                    {
                        string confirmValue = Request.Form["confirm_value"];
                        if (confirmValue == "Yes")
                        {
                            EquipmentService equipmentService = new EquipmentService();
                            EquipmentInsertView insertView = new EquipmentInsertView();

                            insertView.BrandId = Int32.Parse(BrandText.SelectedItem.Value);

                           // insertView.GroupConsecutive = Int32.Parse(EquipmentSubIdText.Text);

                            insertView.GroupId = Int32.Parse(EquipmentGroupText.SelectedItem.Value);
                            insertView.HMIAddress = HMIAddressText.Text;
                            insertView.Id = EquipmentIdText.Text;
                            insertView.Location = LocationText.Text;
                            insertView.Model = ModelText.Text;
                            insertView.PLCAddress = PLCAddressText.Text;
                            insertView.PLCLink = ethernetLink.Items[0].Selected;
                            insertView.Status = EquipmentEnable.Items[0].Selected;

                            CUDView crud = equipmentService.insertEquipment(insertView);

                            if (crud.insert == false)
                            {
                                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the Equipment')", true);
                            }
                            else
                            {
                                clearFields1();
                                fillEquipmentTable();
                            }
                        }
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Equipment Sub Id must be numeric.')", true);
                    }

                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields.')", true);
                }

            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields.')", true);
            }
        }
示例#4
0
 /*
   Funcion: Verifica que el equipo sea valido
   Param: PLCAddress, HMIAddress
   Return: Bool
   */
 public DataTable isEquipmentValid(EquipmentInsertView equipment)
 {
     return context.selectMSQL("Exec isEquipmentValid @EquipmentPLCAddress='"+ equipment.PLCAddress+ "', @EquipmentHMIAddress = '"+ equipment.HMIAddress + "';");
 }
        /*Funcion: Insertar nuevos equipos
          Param: EquipmentInsertView,AuditDataFromWeb
          Return: status
          */
        public CUDView insertEquipment(EquipmentInsertView equipment, AuditDataFromWeb audit)
        {
            int isValid = 0;
            EquipmentDao Dao = new EquipmentDao();
            DataTable isEquipmentValid = Dao.isEquipmentValid(equipment);

            foreach (DataRow row in isEquipmentValid.Rows)
            {
                if (isEquipmentValid.Columns.Contains("equipmentInserted") && row["equipmentInserted"] != DBNull.Value) { isValid = Convert.ToInt32(row["equipmentInserted"]); }

            }

            //Se comprueba que no exista un EquipmentPLCAdress y un EquipmentHMIAdressIguales

            if (isValid == 1)
            {
                String state = Dao.insertEquipment(equipment);
                CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state);

                if (logic.insert == true)
                {
                    AuditService auditservice = new AuditService();
                    String Action = "Insert new equipment";
                    String NewValues = "EquipmentId: " + equipment.Id
                        + ", GroupId: " + equipment.GroupId
                        + ", HMIAddress: " + equipment.HMIAddress
                        + ", Location: " + equipment.Location
                        + ", Model: " + equipment.Model
                        + ", PLCAddress: " + equipment.PLCAddress
                        + ", PLCLink: " + equipment.PLCLink
                        + ", Status: " + equipment.Status;

                    auditservice.formInsert(Action, NewValues, audit);
                }
                return logic;
            }
            else
            {
                CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", "errHMIPLC");
                return logic;
            }
        }