/* Metodo que inserta las unidades desde la ventana de add units */ protected void addUnit_Click(object sender, EventArgs e) { string Name = UnitName.Text; string Symbol = UnitSymbol.Text; if (Name != "" & Symbol != "") { ParameterService parameterService = new ParameterService(); UnitsInsertView unit = new UnitsInsertView(); unit.UnitName = Name; unit.UnitSymbol = Symbol; String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = "N/A"; audit.StationIP = General.getIp(this.Page); audit.UserName = user; CUDView crud = parameterService.insertUnits(unit, audit); if (crud.insert == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the Value')", true); } else { UnitName.Text = ""; UnitSymbol.Text = ""; fillUnitGroupTable(); updateUnitModal.Update(); } } }
/* Metodo para insertar un nuevo producto */ protected void addProcess_Click(object sender, EventArgs e) { string value = ValueProduct.Text; if (value != "") { ProcessService processService = new ProcessService(); String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = "N/A"; audit.StationIP = General.getIp(this.Page); audit.UserName = user; CUDView crud = processService.insertProduct(value, audit); if (crud.insert == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the Value')", true); } else { ValueProduct.Text = ""; fillProductGroupTable(); updateProductModal.Update(); } } }
/*Funcion: construye los datos de un insert Param: Action, NewValues, audit Return: status */ public CUDView formInsert(String Action, String NewValues, AuditDataFromWeb audit) { InsertActionServerAuditTrailView x = new InsertActionServerAuditTrailView(); x.Reason=audit.Reason; x.StationIP=audit.StationIP; x.UserName=audit.UserName; x.Action = Action; x.NewValues = NewValues; return insertAuditTrail(x); }
/*Funcion: construye los datos de un update Param: Action, NewValues, audit, OldValues Return: status */ public CUDView formUpdate(String Action, String NewValues, String OldValues, AuditDataFromWeb audit) { UpdateActionServerAuditTrailView x = new UpdateActionServerAuditTrailView(); x.Reason = audit.Reason; x.StationIP = audit.StationIP; x.UserName = audit.UserName; x.Action = Action; x.NewValues = NewValues; x.OldValues = OldValues; return updateAuditTrail(x); }
/*Funcion: Insertar productos Param: ProductLineName,AuditDataFromWeb Return: status */ public CUDView insertProduct(String ProductLineName, AuditDataFromWeb audit) { ProcessDao Dao = new ProcessDao(); String state = Dao.insertProduct(ProductLineName); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert new ProductLineName"; String NewValues = "ProductLineName: " + ProductLineName; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/*Funcion: insertar procesos Param: ProcessInsertView,AuditDataFromWeb Return: status */ public CUDView insertProcess(ProcessInsertView process, AuditDataFromWeb audit) { ProcessDao Dao = new ProcessDao(); String state = Dao.insertProcess(process); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert new process"; String NewValues = "ProcessName: " + process.ProcessName + ", ProcessParameterSet: " + process.ProcessParameterSet + ", ProcessPlotEnable: " + process.ProcessPlotEnable + ", ProductLineId: " + process.ProductLineId; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/* Metodo para actualizar un grupo */ private void updateGroupAux() { if (HttpContext.Current.Session["EquipmentGroupId"] != null) { string value = ValueGroup.Text; if (value != "") { String reason = Session["reason"].ToString(); String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = reason; audit.StationIP = General.getIp(this.Page); audit.UserName = user; EquipmentService equipmentService = new EquipmentService(); EquipmentGroupView groupView = new EquipmentGroupView(); groupView.EquipmentGroupId = Int32.Parse(HttpContext.Current.Session["EquipmentGroupId"].ToString()); groupView.EquipmentGroupName = value; CUDView crud = equipmentService.UpdateEquipmentGroup(groupView, audit); if (crud.update == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not update the Value')", true); } else { ValueGroup.Text = ""; filEquipmentGroupTable(); upModalSuccess.Update(); } HttpContext.Current.Session["operation"] = "create"; showGroupModal(); } } }
/* Metodo que se utiliza para realizar una actualizacion */ private void updateAuxiliar() { //Se verifica que se haya seleccionado un equipo if (HttpContext.Current.Session["EquipmentId"] != null) { //Se verifica que se hayan completado los espacios HMI, PLC y Location if (HMIAddressText.Text != "" & PLCAddressText.Text != "" & LocationText.Text != "") { //Se obtienen los datos EquipmentService equipmentService = new EquipmentService(); EquipmentUpdateView equipment = new EquipmentUpdateView(); equipment.HMIAddress = HMIAddressText.Text; equipment.Location = LocationText.Text; equipment.PLCAddress = PLCAddressText.Text; equipment.PLCLink = ethernetLink.Items[0].Selected; equipment.Status = EquipmentEnable.Items[0].Selected; equipment.Id = EquipmentIdText.Text; //Se muestra la ventana de justificacion para la actualizacion String reason = Session["reason"].ToString(); String user = Context.User.Identity.Name; //Se llenan los datos para la auditoria AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = reason; audit.StationIP = General.getIp(this.Page); audit.UserName = user; //Se realiza la actualizacion CUDView crud = equipmentService.updateEquipment(equipment, audit); if (crud.update == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not update the Equipment')", true); } clearFields1(); fillEquipmentTable(); } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields.')", true); } } }
/*Funcion: Insertar una operaciom Param: OperationInsertView, AuditDataFromWeb Return: status */ public CUDView insertOperation(OperationInsertView operation, AuditDataFromWeb audit) { OperationDao Dao = new OperationDao(); operation.ID = getOperationID(operation); operation.OperationProcessId = getOperationProcessIdByLastProduct(operation); List<String> state = Dao.insertOperation(operation); CUDView logic = CUDVerifyLogic.verifierInsertPKReturnMSQL("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert new operation"; String NewValues = "OperationId: " + logic.insertPK + ", ID: " + operation.ID + ", OperationName: " + operation.OperationName + ", OperationProcessId: " + operation.OperationProcessId + ", OperationTypeId: " + operation.OperationTypeId + ", ProcessId: " + operation.ProcessId + ", ProductLineId: " + operation.ProductLineId; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/* Metodo que se utiliza para hacer una insercion de un nuevo proceso */ private void saveAuxiliar() { if (ProductText.SelectedItem != null) { if (ProcessText.Text != "" & ProductText.SelectedItem.Value != "") { ProcessService processService = new ProcessService(); ProcessInsertView insertView = new ProcessInsertView(); insertView.ProcessName = ProcessText.Text; insertView.ProductLineId = Int32.Parse(ProductText.SelectedItem.Value); insertView.ProcessParameterSet = parameterSetText.Items[0].Selected; insertView.ProcessPlotEnable = plotEnableText.Items[0].Selected; String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = "N/A"; audit.StationIP = General.getIp(this.Page); audit.UserName = user; CUDView crud = processService.insertProcess(insertView, audit); if (crud.insert == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the Process')", true); } else { clearFields(); fillProcessTable(); } } 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); } }
/* Metodo para realizar una insersion */ private void saveAuxiliar() { if (Upn2.Text != "" & ProcessSelector.SelectedItem != null & Product2.SelectedItem != null) { if (ProcessSelector.SelectedItem.Value != "" & Product2.SelectedItem.Value != "") { if (validateRecipeonOperation() & checkEnableRecipeInsert()) { UpnService upnService = new UpnService(); UpnInsertView upn = new UpnInsertView(); upn.ProductLineId = Int32.Parse(Product2.SelectedItem.Value); upn.UpnId = Upn2.Text; upn.UPNStatus = upnEnable2.Items[0].Selected; upn.Multisession = multisessionCheck.Items[0].Selected; upn.UpnTypeId = 0; // cambiar, esta alambrado String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = "N/A"; audit.StationIP = General.getIp(this.Page); audit.UserName = user; CUDView crud = upnService.insertUpn(upn, audit); if (crud.insert == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the UPN')", true); } else { foreach (GridViewRow gvrow in GridView2.Rows) { CheckBox operationEnable = (CheckBox)gvrow.FindControl("EnableOperation"); Label lblOperationId = (Label)gvrow.FindControl("OperationId"); Label lblRecipeId = (Label)gvrow.FindControl("recipeOperationId"); Label lblRecipe = (Label)gvrow.FindControl("recipeOperation"); if (lblRecipe.Text != "") { UpnInsertOperationView newOperationUpn = new UpnInsertOperationView(); newOperationUpn.OperationEnable = operationEnable.Checked; newOperationUpn.OperationId = Int32.Parse(lblOperationId.Text); newOperationUpn.ProcessId = Int32.Parse(ProcessSelector.SelectedItem.Value); newOperationUpn.RecipeId = Int32.Parse(lblRecipeId.Text); newOperationUpn.UpnId = upn.UpnId; crud = upnService.insertUpnOperation(newOperationUpn, audit); } } if (crud.insert == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the operation')", true); } fillUpnTable(); Upn.Text = ""; Product.Text = ""; clearOperationTable(); clearProcesses(); fillProducts(); clearRecipeUpn(); FirstDIV.Visible = true; SecondDIV.Visible = false; } } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Add at least one enabled recipe to operation table.')", 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); } }
/*Funcion: actualizar parametros Param: ParameterUpdateView,AuditDataFromWeb Return: status */ public CUDView updateParameter(ParameterUpdateView parameter, AuditDataFromWeb audit) { AuditDao auditDao = new AuditDao(); DataTable auditDaoResult = auditDao.getParameterByParameterID(parameter.ParameterId); String OldValues = "ParameterId: " + parameter.ParameterId; foreach (DataRow row in auditDaoResult.Rows) { if (auditDaoResult.Columns.Contains("ParameterMinValue") && row["ParameterMinValue"] != DBNull.Value) { OldValues = OldValues + ", ParameterMinValue: " + Convert.ToDouble(row["ParameterMinValue"]); } if (auditDaoResult.Columns.Contains("ParameterName") && row["ParameterName"] != DBNull.Value) { OldValues = OldValues + ", ParameterName: " + row["ParameterName"].ToString(); } if (auditDaoResult.Columns.Contains("ParameterXPlot") && row["ParameterXPlot"] != DBNull.Value) { OldValues = OldValues + ", ParameterXPlot: " + (bool)row["ParameterXPlot"]; } if (auditDaoResult.Columns.Contains("ParameterYPlot") && row["ParameterYPlot"] != DBNull.Value) { OldValues = OldValues + ", ParameterYPlot: " + (bool)row["ParameterYPlot"]; } if (auditDaoResult.Columns.Contains("ParameterYPlotRange") && row["ParameterYPlotRange"] != DBNull.Value) { OldValues = OldValues + ", ParameterYPlotRange: " + Convert.ToInt32(row["ParameterYPlotRange"]); } if (auditDaoResult.Columns.Contains("ProcessId") && row["ProcessId"] != DBNull.Value) { OldValues = OldValues + ", ProcessId: " + Convert.ToInt32(row["ProcessId"]); } if (auditDaoResult.Columns.Contains("UnitId") && row["UnitId"] != DBNull.Value) { OldValues = OldValues + ", UnitId: " + row["UnitId"].ToString(); } } ParameterDao Dao = new ParameterDao(); String state = Dao.updateParameter(parameter); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("update", state); if (logic.update == true) { AuditService auditservice = new AuditService(); String Action = "Update parameter"; String NewValues = "ParameterId: " + parameter.ParameterId + ", ParameterMinValue: " + parameter.ParameterMinValue + ", ParameterName: " + parameter.ParameterName + ", ParameterXPlot: " + parameter.ParameterXPlot + ", ParameterYPlot: " + parameter.ParameterYPlot + ", ParameterYPlotRange: " + parameter.ParameterYPlotRange + ", ProcessId: " + parameter.ProcessId + ", UnitId: " + parameter.UnitId; auditservice.formUpdate(Action, NewValues, OldValues, audit); } return logic; }
/*Funcion: Insertar el equipo para una receta Param: RecipeEquipmentInsertView, AuditDataFromWeb Return: Status */ public CUDView insertRecipeEquipment(RecipeEquipmentInsertView recipeEquipmentInsertView, AuditDataFromWeb audit) { RecipeDao Dao = new RecipeDao(); String state = Dao.insertRecipeEquipment(recipeEquipmentInsertView); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert recipe equipment"; String NewValues = "RecipeId: " + recipeEquipmentInsertView.RecipeId + ", EquipmentId: " + recipeEquipmentInsertView.EquipmentId + ", OperationId: " + recipeEquipmentInsertView.OperationId + ", Link: " + recipeEquipmentInsertView.Link; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/*Funcion: insertar una receta Param: RecipeInsertView,AuditDataFromWeb Return: Lista RecipeParameterView */ public CUDView insertRecipe(RecipeInsertView recipe, AuditDataFromWeb audit) { CUDView logic = new CUDView(); RecipeDao Dao = new RecipeDao(); int operationProcessID = 0; DataTable DaoResultIsTest = Dao.isTest(recipe.OperationId); foreach (DataRow row in DaoResultIsTest.Rows) { if (DaoResultIsTest.Columns.Contains("OperationProcessId") && row["OperationProcessId"] != DBNull.Value) { operationProcessID = Convert.ToInt32(row["OperationProcessId"]); } } if (operationProcessID == 0) { int countRecipeTest = 0; DataTable DaoResultCountRecipeTest = Dao.hasRecipeTest(); foreach (DataRow row in DaoResultCountRecipeTest.Rows) { if (DaoResultCountRecipeTest.Columns.Contains("RecipeTest") && row["RecipeTest"] != DBNull.Value) { countRecipeTest = Convert.ToInt32(row["RecipeTest"]); } } if (countRecipeTest > 0) { logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", "There is already a recipe with 'test' operation."); } else { List<String> state = Dao.insertRecipe(recipe); logic = CUDVerifyLogic.verifierInsertPKReturnMSQL("insert", state); } } else { List<String> state = Dao.insertRecipe(recipe); logic = CUDVerifyLogic.verifierInsertPKReturnMSQL("insert", state); } if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert new recipe"; String NewValues = "RecipeId: " + logic.insertPK + ", RecipeEnable: " + recipe.RecipeEnable + ", OperationId: " + recipe.OperationId + ", ProcessId: " + recipe.ProcessId; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/*Funcion: actualizar productos Param: ProductUpdateView,AuditDataFromWeb Return: Lista Units */ public CUDView updateProduct(ProductUpdateView product, AuditDataFromWeb audit) { CUDView logic = new CUDView(); AuditDao auditDao = new AuditDao(); DataTable auditDaoResult = auditDao.getProductsOldValues(product.ProductLineId); String OldValues = "ProductId: " + product.ProductLineId; foreach (DataRow row in auditDaoResult.Rows) { if (auditDaoResult.Columns.Contains("Product") && row["Product"] != DBNull.Value) { OldValues = OldValues + ", Product: " + row["Product"].ToString(); } } ProcessDao Dao = new ProcessDao(); String state = Dao.updateProduct(product); logic=CUDVerifyLogic.verifierInsertDeleteUpdate("update", state); if (logic.update == true) { AuditService auditservice = new AuditService(); String Action = "Update Product"; String newValues = "ProductId: " + product.ProductLineId; newValues = newValues + ", Product: " + product.ProductLineName; auditservice.formUpdate(Action, newValues, OldValues, audit); } return logic; }
/*Funcion: Insertar operacion de un equipo Param: OperationEquipmentInsertView, AuditDataFromWeb Return: status */ public CUDView insertOperationEquipment(OperationEquipmentInsertView operation, AuditDataFromWeb audit) { OperationDao Dao = new OperationDao(); String state = Dao.insertOperationEquipment(operation); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert new equipment for operation"; String NewValues = "OperationId: " + operation.OperationId + ", EquipmentId: " + operation.EquipmentId; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/*Funcion: insertar parametros Param: ParameterInsertView,AuditDataFromWeb Return: status */ public CUDView insertParameter(ParameterInsertView parameter, AuditDataFromWeb audit) { ParameterDao Dao = new ParameterDao(); String state = Dao.insertParameter(parameter); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert new parameter"; String NewValues = "ParameterName: " + parameter.ParameterName + ", ParameterMinValue: " + parameter.ParameterMinValue + ", ParameterXPlot: " + parameter.ParameterXPlot + ", ParameterYPlot: " + parameter.ParameterYPlot + ", ParameterYPlotRange: " + parameter.ParameterYPlotRange + ", ProcessId: " + parameter.ProcessId + ", UnitId: " + parameter.UnitId; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/*Funcion: Insertar un parametro para la receta Param: RecipeParameterInsertView,AuditDataFromWeb Return: Status */ public CUDView InsertRecipeParameter(RecipeParameterInsertView parameter, AuditDataFromWeb audit) { RecipeDao Dao = new RecipeDao(); String state = Dao.InsertRecipeParameter(parameter); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert recipe parameter"; String NewValues = "RecipeId: " + parameter.RecipeId + ", ParameterId: " + parameter.ParameterId + ", ParameterValue: " + parameter.ParameterValue; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/*Funcion: Insertar Units Param: UnitsInsertView,AuditDataFromWeb Return: Lista Units */ public CUDView insertUnits(UnitsInsertView unit, AuditDataFromWeb audit) { ParameterDao Dao = new ParameterDao(); String state = Dao.insertUnits(unit); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("insert", state); if (logic.insert == true) { AuditService auditservice = new AuditService(); String Action = "Insert new unit"; String NewValues = "UnitName: " + unit.UnitName + ", UnitSymbol: " + unit.UnitSymbol; auditservice.formInsert(Action, NewValues, audit); } return logic; }
/*Funcion: actualizar una receta Param: recipeId,AuditDataFromWeb Return: status */ public CUDView updateRecipe(RecipeUpdateView recipe, AuditDataFromWeb audit) { CUDView logic = new CUDView(); AuditDao auditDao = new AuditDao(); DataTable auditDaoResult = auditDao.getRecipeOldValues(recipe.RecipeId); String OldValues = "RecipeId: " + recipe.RecipeId; foreach (DataRow row in auditDaoResult.Rows) { if (auditDaoResult.Columns.Contains("RecipeStatus") && row["RecipeStatus"] != DBNull.Value) { OldValues = OldValues + ", RecipeEnable: " + (bool)row["RecipeStatus"]; } } RecipeDao Dao = new RecipeDao(); String state = Dao.updateRecipe(recipe); logic = CUDVerifyLogic.verifierInsertDeleteUpdate("update", state); if (logic.update == true) { AuditService auditservice = new AuditService(); String Action = "Update recipe"; String NewValues = "RecipeId: " + recipe.RecipeId + ", RecipeEnable: " + recipe.RecipeEnable ; auditservice.formUpdate(Action, NewValues, OldValues, audit); } return logic; }
/*Funcion: Actualizar Units Param: UnitView,AuditDataFromWeb Return: Status */ public CUDView updateUnits(UnitView unit, AuditDataFromWeb audit) { AuditDao auditDao = new AuditDao(); DataTable auditDaoResult = auditDao.getUnitByUnitId(unit.UnitId); String OldValues = "UnitId: " + unit.UnitId; foreach (DataRow row in auditDaoResult.Rows) { if (auditDaoResult.Columns.Contains("UnitName") && row["UnitName"] != DBNull.Value) { OldValues = OldValues + ", UnitName: " + row["UnitName"].ToString(); } if (auditDaoResult.Columns.Contains("UnitSymbol") && row["UnitSymbol"] != DBNull.Value) { OldValues = OldValues + ", UnitSymbol: " + row["UnitSymbol"].ToString(); } } ParameterDao Dao = new ParameterDao(); String state = Dao.updateUnits(unit); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("update", state); if (logic.update == true) { AuditService auditservice = new AuditService(); String Action = "Update unit"; String NewValues = "UnitId: " + unit.UnitId + ", UnitName: " + unit.UnitName + ", UnitSymbol: " + unit.UnitSymbol; auditservice.formUpdate(Action, NewValues, OldValues, audit); } return logic; }
/* Metodo que se utiliza para actualizar un proceso existente */ private void updateAuxiliar() { if (HttpContext.Current.Session["ProcessId"] != null) { String reason = Session["reason"].ToString(); String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = reason; audit.StationIP = General.getIp(this.Page); audit.UserName = user; ProcessService processService = new ProcessService(); ProcessUpdateView processUpdate = new ProcessUpdateView(); processUpdate.ProcessId = Int32.Parse(HttpContext.Current.Session["ProcessId"].ToString()); processUpdate.ProcessPlotEnable = plotEnableText.Items[0].Selected; CUDView crud = processService.updateProcess(processUpdate,audit); if (crud.update == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not update the Process')", true); } else { clearFields(); fillProcessTable(); } } }
/* Metodo para realizar una actualizacion */ private void updateAuxiliar() { if (HttpContext.Current.Session["IdUpn"] != null) { if (Upn.Text != "" & ProcessSelector1.SelectedItem != null) { if (validateRecipeonOperationUpdate() & checkEnableRecipeUpdate()) { UpnService upnService = new UpnService(); UpnUpdateView upn = new UpnUpdateView(); upn.UpnId = Upn.Text; upn.UpnStatus = upnEnable.Items[0].Selected; upn.Multisession = multisessionEnable.Items[0].Selected; String reason = Session["reason"].ToString(); String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = reason; audit.StationIP = General.getIp(this.Page); audit.UserName = user; CUDView crud = upnService.updateUpn(upn, audit); String processSelectorId = ProcessSelector1.SelectedItem.Value; String upnId = upn.UpnId; if (crud.update == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not update the UPN')", true); } else { foreach (GridViewRow gvrow in GridView1.Rows) { CheckBox operationEnable = (CheckBox)gvrow.FindControl("EnableOperation1"); Label lblOperationId = (Label)gvrow.FindControl("OperationId1"); Label lblRecipeId = (Label)gvrow.FindControl("recipeOperationId1"); Label lblRecipe = (Label)gvrow.FindControl("recipeOperation1"); if (lblRecipe.Text != "") { UpnOperationView newOperationUpn = new UpnOperationView(); newOperationUpn.Enable = operationEnable.Checked; newOperationUpn.OperationId = Int32.Parse(lblOperationId.Text); newOperationUpn.ProcessId = Int32.Parse(processSelectorId); newOperationUpn.RecipeId = Int32.Parse(lblRecipeId.Text); newOperationUpn.UpnId = upnId; crud = upnService.updateUpnOperation(newOperationUpn, audit); } } if (crud.update == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not update the operation')", true); } } fillUpnTable(); Upn.Text = ""; Product.Text = ""; clearOperationTable1(); clearProcesses1(); clearRecipeUpn1(); RecipeUpn1.Enabled = false; GridView1.Enabled = false; upnEnable.Items[0].Enabled = false; upnEnable.Items[0].Selected = false; multisessionEnable.Items[0].Enabled = false; multisessionEnable.Items[0].Selected = false; } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Add at least one enabled recipe to operation table.')", true); } } } }
/* Metodo utilizado para insertar recipes */ private void saveAuxiliar() { if (Product2.SelectedItem != null & Process2.SelectedItem != null & Operation2.SelectedItem != null) { if (Process2.SelectedItem.Value != "" & Operation2.SelectedItem.Value != "") { if (validateParameterOnRecipeInsert()) { if (validatetableParameterOneForInt()) { //Crea el servicio RecipeService recipeService = new RecipeService(); RecipeInsertView recipe = new RecipeInsertView(); recipe.ProcessId = Int32.Parse(Process2.SelectedItem.Value); recipe.OperationId = Int32.Parse(Operation2.SelectedItem.Value); recipe.RecipeEnable = recipeEnable2.Items[0].Selected; String user = Context.User.Identity.Name; String reason = "N/A"; //AƱade los datos para la auditoria AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = reason; audit.StationIP = General.getIp(this.Page); audit.UserName = user; //Realiza la insercion CUDView crud = recipeService.insertRecipe(recipe, audit); string idRecipNew = crud.insertPK; if (crud.insert == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the recipe')", true); } else { //Insert Parameters foreach (GridViewRow gvrow in GridView4.Rows) { Label lblParameterId = (Label)gvrow.FindControl("ParameterId"); TextBox lblValue = (TextBox)gvrow.FindControl("Value"); if (lblValue.Text != "") { RecipeParameterInsertView newParameter = new RecipeParameterInsertView(); newParameter.ParameterId = Int32.Parse(lblParameterId.Text); newParameter.ParameterValue = Int32.Parse(lblValue.Text); newParameter.RecipeId = Int32.Parse(idRecipNew); crud = recipeService.InsertRecipeParameter(newParameter, audit); } } //Insert Equipments foreach (GridViewRow gvrow in GridView5.Rows) { CheckBox chk = (CheckBox)gvrow.FindControl("Link"); Label lblID = (Label)gvrow.FindControl("ID"); Label lblEquipment = (Label)gvrow.FindControl("EquipmentName"); RecipeEquipmentInsertView newEquipment = new RecipeEquipmentInsertView(); newEquipment.EquipmentId = lblID.Text; newEquipment.Link = chk.Checked; newEquipment.RecipeId = Int32.Parse(idRecipNew); newEquipment.OperationId = recipe.OperationId; crud = recipeService.insertRecipeEquipment(newEquipment, audit); } clearFields(); } } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('All parameter values must be numbers')", true); } } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please add parameters for this process.')", 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); } }
/*Funcion: actualizar equipos de la receta Param: RecipeEquipmentView,AuditDataFromWeb Return: status */ public CUDView updateRecipeEquipment(RecipeEquipmentView recipe, AuditDataFromWeb audit) { AuditDao auditDao = new AuditDao(); DataTable auditDaoResult = auditDao.getRecipeEquipmentByRecipeEquipMentIdAndRecipeId(recipe.RecipeId, recipe.RecipeEquipmentId); String OldValues = "RecipeId: " + recipe.RecipeId; foreach (DataRow row in auditDaoResult.Rows) { if (auditDaoResult.Columns.Contains("RecipeEquipmentId") && row["RecipeEquipmentId"] != DBNull.Value) { OldValues = OldValues + ", RecipeEquipmentId: " + Convert.ToInt32(row["RecipeEquipmentId"]); } if (auditDaoResult.Columns.Contains("Link") && row["Link"] != DBNull.Value) { OldValues = OldValues + ", Link: " + (bool)row["Link"]; } } //Update RecipeDao Dao = new RecipeDao(); String state = Dao.updateRecipeEquipment(recipe); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("update", state); //Fin update if (logic.update == true) { AuditService auditservice = new AuditService(); String Action = "Update recipe equipment"; String NewValues = "RecipeId: " + recipe.RecipeId + ", RecipeEquipmentId: " + recipe.RecipeEquipmentId + ", Link: " + recipe.Link; auditservice.formUpdate(Action, NewValues, OldValues, audit); } return logic; }
/*Funcion: actualiza un Upn por operacion Param: upnUpdateView, AuditDataFromWeb Return: Status */ public CUDView updateUpnOperation(UpnOperationView upnUpdateView, AuditDataFromWeb audit) { CUDView logic = new CUDView(); AuditDao auditDao = new AuditDao(); DataTable auditDaoResult = auditDao.getUpnOperatoinOldValues(upnUpdateView.UpnId,upnUpdateView.ProcessId,upnUpdateView.OperationId); String OldValues = "UpnId: " + upnUpdateView.UpnId; foreach (DataRow row in auditDaoResult.Rows) { if (auditDaoResult.Columns.Contains("RecipeId") && row["RecipeId"] != DBNull.Value) { OldValues = OldValues + ", RecipeId: " + row["RecipeId"].ToString(); } if (auditDaoResult.Columns.Contains("Enable") && row["Enable"] != DBNull.Value) { OldValues = OldValues + ", Enable: " + row["Enable"].ToString(); } } UpnDao Dao = new UpnDao(); String state = Dao.updateUpnOperation(upnUpdateView); logic=CUDVerifyLogic.verifierInsertDeleteUpdate("update", state); if (logic.update == true) { AuditService auditservice = new AuditService(); String Action = "Update upnOperation"; String newValues = "UpnId: " + upnUpdateView.UpnId; newValues = newValues + ", RecipeId: " + upnUpdateView.RecipeId; newValues = newValues + ", Enable: " + upnUpdateView.Enable; auditservice.formUpdate(Action, newValues, OldValues, audit); } return logic; }
/* Metodo para actualizar un producto */ private void updateProcessGroupAux() { if (HttpContext.Current.Session["ProductId"] != null) { string value = ValueProduct.Text; if (value != "") { ProcessService processService = new ProcessService(); ProductUpdateView ProductsView = new ProductUpdateView(); String reason = Session["reason"].ToString(); String user = Context.User.Identity.Name; AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = reason; audit.StationIP = General.getIp(this.Page); audit.UserName = user; ProductsView.ProductLineId = Int32.Parse(HttpContext.Current.Session["ProductId"].ToString()); ProductsView.ProductLineName = value; CUDView crud = processService.updateProduct(ProductsView,audit); if (crud.update == false) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not update the Value')", true); } else { ValueProduct.Text = ""; fillProductGroupTable(); updateProductModal.Update(); } HttpContext.Current.Session["operation"] = "create"; showProductModal(); } } }
/*Funcion: actualizar datos receta Param: RecipeUpdateValueView,AuditDataFromWeb Return: status */ public CUDView updateRecipeValue(RecipeUpdateValueView recipe, AuditDataFromWeb audit) { AuditDao auditDao = new AuditDao(); DataTable auditDaoResult = auditDao.getRecipeParameterByRecipeIdAndParameterId(recipe.RecipeId, recipe.ParameterId); String OldValues = "RecipeId: " + recipe.RecipeId; foreach (DataRow row in auditDaoResult.Rows) { if (auditDaoResult.Columns.Contains("ParameterId") && row["ParameterId"] != DBNull.Value) { OldValues = OldValues + ", ParameterId: " + Convert.ToInt32(row["ParameterId"]); } if (auditDaoResult.Columns.Contains("ParameterValue") && row["ParameterValue"] != DBNull.Value) { OldValues = OldValues + ", ParameterValue: " + Convert.ToInt32(row["ParameterValue"]); } } //Update RecipeDao Dao = new RecipeDao(); String state = Dao.updateRecipeValue(recipe); CUDView logic = CUDVerifyLogic.verifierInsertDeleteUpdate("update", state); //Fin update if (logic.update == true) { AuditService auditservice = new AuditService(); String Action = "Update recipe parameter value"; String NewValues = "RecipeId: " + recipe.RecipeId + ", ParameterId: " + recipe.ParameterId + ", ParameterValue: " + recipe.ParameterValue; auditservice.formUpdate(Action, NewValues, OldValues, audit); } return logic; }
/* Metodo para realizar una actualizacion de un recipe */ private void updateAuxiliar() { //Verifica que un recipe haya sido seleccionado if (HttpContext.Current.Session["IdRecipe"] != null) { if (validatetableParameterTwoForInt()) { //Crea el servicio RecipeService recipeService = new RecipeService(); RecipeUpdateView recipe = new RecipeUpdateView(); recipe.RecipeId = Int32.Parse(HttpContext.Current.Session["IdRecipe"].ToString()); recipe.RecipeEnable = recipeEnable.Items[0].Selected; String reason = Session["reason"].ToString(); String user = Context.User.Identity.Name; //Llena los datos de la auditoria AuditDataFromWeb audit = new AuditDataFromWeb(); audit.Reason = reason; audit.StationIP = General.getIp(this.Page); audit.UserName = user; //Realiza la actualizaciĆ³n CUDView crud = recipeService.updateRecipe(recipe, audit); if (crud.update == true) { int idRecipe = Int32.Parse(HttpContext.Current.Session["IdRecipe"].ToString()); //Update Parameters foreach (GridViewRow gvrow in GridView1.Rows) { Label lblParameterId = (Label)gvrow.FindControl("ParameterId"); TextBox lblValue = (TextBox)gvrow.FindControl("Value"); if (lblValue.Text != "") { RecipeUpdateValueView newParameter = new RecipeUpdateValueView(); newParameter.ParameterValue = Int32.Parse(lblValue.Text); newParameter.RecipeId = idRecipe; newParameter.ParameterId = Int32.Parse(lblParameterId.Text); crud = recipeService.updateRecipeValue(newParameter, audit); } } //Update Equipments foreach (GridViewRow gvrow in GridView2.Rows) { CheckBox chk = (CheckBox)gvrow.FindControl("Link"); Label lblID = (Label)gvrow.FindControl("ID"); Label RecipeEquipmentId = (Label)gvrow.FindControl("RecipeEquipmentId"); RecipeEquipmentView newEquipment = new RecipeEquipmentView(); newEquipment.RecipeId = idRecipe; newEquipment.EquipmentId = lblID.Text; newEquipment.Link = chk.Checked; newEquipment.RecipeEquipmentId = Int32.Parse(RecipeEquipmentId.Text); crud = recipeService.updateRecipeEquipment(newEquipment, audit); } clearFields(); } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + crud.errorMessage + "')", true); } } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('All parameter values must be numbers')", true); } } }
/* 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); } }