protected void btnCreateDevice_Click(object sender, EventArgs e) { string imei = rtxtIMEI.Text.Trim(); if (imei != "") { DeviceWithResult d = (DeviceWithResult)Device.GetDevice(imei); if (d == null) { d = new DeviceWithResult { IMEI = imei, Model = rtxtModel.Text, Provider = rtxtProvider.Text, OrderNumber = "", UnitId = int.Parse(ddlUnit.SelectedValue), TypeId = int.Parse(ddlType.SelectedValue), Notes = $"Oprettet under mønstring {DateTime.Today.ToString("yyyyMMdd")}" }; if (d.Save()) { d.Result = "Oprettet"; phCreate.Visible = false; imgWarning.Visible = false; lblWarning.Visible = false; rptOtherDevices.Visible = false; lblIMEI.Text = imei; hdnIMEI.Value = imei; } else { d.Result = "Noget gik galt"; } } else { d.Result = "Findes i forvejen"; } lblCreateMsg.Text = d.Result; lblCreateMsg.Visible = true; } }
protected void btnInsert_Click(object sender, EventArgs e) { Validate(); if (Page.IsValid && gvDevices.Rows.Count > 1) { List <DeviceWithResult> results = new List <DeviceWithResult>(); foreach (GridViewRow row in gvDevices.Rows) { if (row.RowType == DataControlRowType.DataRow) { string imei = ((TextBox)row.FindControl("txtIMEI")).Text.Trim(); if (imei != "") { DeviceWithResult d = (DeviceWithResult)AppCode.Device.GetDevice(imei); if (d == null) { d = new DeviceWithResult { IMEI = imei, Model = ((TextBox)row.FindControl("txtModel")).Text, Provider = ((TextBox)row.FindControl("txtProvider")).Text, OrderNumber = ((TextBox)row.FindControl("txtOrderNumber")).Text, UnitId = int.Parse(((DropDownList)row.FindControl("ddlUnit")).SelectedValue), TypeId = int.Parse(((DropDownList)row.FindControl("ddlType")).SelectedValue) }; string buyDate = ((TextBox)row.FindControl("txtBuyDate")).Text; if (buyDate.Trim() != "") { d.BuyDate = DateTime.Parse(buyDate); } if (d.Save()) { d.Result = "Oprettet"; } else { d.Result = "Noget gik galt"; } } else { d.Result = "Findes i forvejen"; } results.Add(d); } } } gvResult.DataSource = results; gvResult.DataBind(); AddRowsToGrid(); } }