public ObjectSensorModelDLL getObjectSensorByID(int objectSensorID) { ObjectSensorModelDLL model = new ObjectSensorModelDLL(); string query = "select * from [ObjectSensors] where ObjectSensorID = @ObjectSensorID"; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ObjectSensorID", objectSensorID), }; using (DataTable table = DBHelper.ExecuteParamerizedSelectCommand(query, CommandType.Text, parameters)) { if (table.Rows.Count == 1) { DataRow row = table.Rows[0]; model.SensorID = Convert.ToInt32(row["SensorID"]); model.ObjectID = Convert.ToInt32(row["ObjectID"]); model.Name = row["Name"].ToString(); model.SMSAlert = Convert.ToBoolean(row["SMSAlert"]); model.EmailAlert = Convert.ToBoolean(row["EmailAlert"]); model.A0 = Convert.ToDouble(row["A0"]); model.A1 = Convert.ToDouble(row["A1"]); model.Contact = row["Contact"].ToString(); model.Min = Convert.ToInt32(row["Min"]); model.Max = Convert.ToInt32(row["Max"]); model.CategoryID = Convert.ToInt32(row["CategoryID"]); } } return(model); }
protected void linkbtnEdit_Command(object sender, CommandEventArgs e) { try { if (e.CommandName == "UpdateID") { btnAddObjectSensor.Text = "Update"; allowStaticMethods("applyDatatable('.gvdObjectSensorClass');staticMethod('Enable');"); int cmdArg = Convert.ToInt32(e.CommandArgument); ObjectSensorModelDLL li = obj.getObjectSensorByID(cmdArg); ddlSensorBind(); ddlSensor.SelectedValue = li.SensorID.ToString(); txtName.Text = li.Name; txtMax.Text = li.Max.ToString(); txtMin.Text = li.Min.ToString(); txta0.Text = li.A0.ToString(); txta1.Text = li.A1.ToString(); txtContact.Text = li.Contact; cbSmsAlert.Checked = Convert.ToBoolean(li.SMSAlert); ddlcategory.SelectedValue = li.CategoryID.ToString(); Session["objectsensorId"] = cmdArg.ToString(); } } catch (Exception) { BindingClass.ExceptionAlertScriptManager(this.Page, this.GetType()); } }
public bool postObjectSensor(ObjectSensorModelDLL _object) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ObjectSensorId", _object.ObjectSensorId), new SqlParameter("@SensorID", _object.SensorID), new SqlParameter("@ObjectID", _object.ObjectID), new SqlParameter("@Name", _object.Name), new SqlParameter("@SMSAlert", _object.SMSAlert), new SqlParameter("@EmailAlert", _object.EmailAlert), new SqlParameter("@A1", _object.A1), new SqlParameter("@A0", _object.A0), new SqlParameter("@Contact", _object.Contact), new SqlParameter("@Min", _object.Min), new SqlParameter("@Max", _object.Max), new SqlParameter("@CategoryID", _object.CategoryID), }; return(DBHelper.ExecuteNonQuery("uspPOST_ObjectSensor", CommandType.StoredProcedure, parameters)); }
protected void btnAddObjectSensor_Click(object sender, EventArgs e) { try { if (ddlClient.SelectedValue != "0" && ddlcategory.SelectedValue != "0" && ddlObject.SelectedValue != "0" && ddlSensor.SelectedValue != "0" && txtName.Text != "" && txtMax.Text != "" && txtMin.Text != "" && txta1.Text != "" && txta0.Text != "") { ObjectSensorModelDLL model = new ObjectSensorModelDLL(); model.ObjectID = Convert.ToInt32(ddlObject.SelectedValue); model.SensorID = Convert.ToInt32(ddlSensor.SelectedValue); model.Name = txtName.Text; model.SMSAlert = cbSmsAlert.Checked; model.EmailAlert = false; model.Contact = txtContact.Text + ","; model.Max = Convert.ToInt32(txtMax.Text); model.Min = Convert.ToInt32(txtMin.Text); model.A1 = Convert.ToDouble(txta1.Text); model.A0 = Convert.ToDouble(txta0.Text); model.CategoryID = Convert.ToInt32(ddlcategory.SelectedValue); if (btnAddObjectSensor.Text == "Save") { model.ObjectSensorId = 0; bool exist = obj.objectSensorExist(model.ObjectID, model.SensorID); if (exist == false) { bool status = obj.postObjectSensor(model); if (status == true) { alert = AlertsClass.SuccessAdd; } else { alert = AlertsClass.ErrorWentWrong; } } else { alert = AlertsClass.ErrorExist("Device Sensor "); } } if (btnAddObjectSensor.Text == "Update") { model.ObjectSensorId = Convert.ToInt64(Session["objectsensorId"]); bool status = obj.postObjectSensor(model); if (status == true) { alert = AlertsClass.SuccessAdd; } else { alert = AlertsClass.ErrorWentWrong; } } } else { alert = AlertsClass.ErrorRequired; } clearControls(); ddlNAsensorBind(); gridBind(); allowStaticMethods("ALerts('" + alert + "');applyDatatable('.gvdObjectSensorClass');staticMethod('Disable');"); } catch (Exception) { BindingClass.ExceptionAlertScriptManager(this.Page, this.GetType()); } }
public bool postObjectSensor(ObjectSensorModelDLL _object) { return(obj.postObjectSensor(_object)); }