protected void ctlSubmit_Click(object sender, ImageClickEventArgs e) { IList <DbZoneLang> zoneLangList = new List <DbZoneLang>(); DbZone zone = new DbZone(UIHelper.ParseShort(ctlZoneGridView.SelectedValue.ToString())); foreach (GridViewRow row in ctlZoneLangGrid.Rows) { TextBox ctlZoneName = (TextBox)ctlZoneLangGrid.Rows[row.RowIndex].FindControl("ctlZoneName"); TextBox ctlComment = (TextBox)ctlZoneLangGrid.Rows[row.RowIndex].FindControl("ctlComment"); CheckBox ctlActiveChk = (CheckBox)ctlZoneLangGrid.Rows[row.RowIndex].FindControl("ctlActive"); if (!string.IsNullOrEmpty(ctlZoneName.Text) || !string.IsNullOrEmpty(ctlComment.Text)) { DbZoneLang zoneLang = new DbZoneLang(); DbLanguage Lang = new DbLanguage(UIHelper.ParseShort(ctlZoneLangGrid.DataKeys[row.RowIndex].Value.ToString())); zoneLang.Language = Lang; zoneLang.Zone = zone; zoneLang.ZoneName = ctlZoneName.Text; zoneLang.Comment = ctlComment.Text; zoneLang.Active = ctlActiveChk.Checked; zoneLang.CreBy = UserAccount.UserID; zoneLang.CreDate = DateTime.Now; zoneLang.UpdBy = UserAccount.UserID; zoneLang.UpdDate = DateTime.Now; zoneLang.UpdPgm = ProgramCode; zoneLangList.Add(zoneLang); } } DbZoneLangService.UpdateZoneLang(zoneLangList); ctlMessage.Message = GetMessage("SaveSuccessFully"); }
protected void ctlZoneForm_ItemInserting(object sender, FormViewInsertEventArgs e) { TextBox ctlZoneName = (TextBox)ctlZoneForm.FindControl("ctlZoneName"); DbZoneLang zoneLang = new DbZoneLang(); DbZone zone = new DbZone(); GetZoneInfo(zone, "Insert"); zoneLang.Zone = zone; zoneLang.Language = DbLanguageService.FindByIdentity(UIHelper.ParseShort(UserAccount.CurrentLanguageID.ToString())); zoneLang.ZoneName = ctlZoneName.Text; zoneLang.CreBy = UserAccount.UserID; zoneLang.CreDate = DateTime.Now; zoneLang.UpdBy = UserAccount.UserID; zoneLang.UpdDate = DateTime.Now; zoneLang.UpdPgm = ProgramCode; zoneLang.Active = true; try { DbZoneLangService.AddZoneLang(zone, zoneLang); ctlZoneGridView.DataCountAndBind(); ctlZoneForm.ChangeMode(FormViewMode.ReadOnly); CloseZonePopUp(); } catch (ServiceValidationException ex) { ValidationErrors.MergeErrors(ex.ValidationErrors); } }
protected void ctlDelete_Click(object sender, ImageClickEventArgs e) { foreach (GridViewRow row in ctlZoneGridView.Rows) { if ((row.RowType == DataControlRowType.DataRow) && (((CheckBox)row.FindControl("ctlSelectChk")).Checked)) { try { short zoneId = UIHelper.ParseShort(ctlZoneGridView.DataKeys[row.RowIndex].Value.ToString()); DbZone zone = SsDbQueryProvider.DbZoneQuery.FindProxyByIdentity(zoneId); DbZoneService.Delete(zone); ZoneLangGridViewFinish(); } catch (Exception ex) { if (((System.Data.SqlClient.SqlException)(ex.GetBaseException())).Number == 547) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertInUseData", "alert('This data is now in use.');", true); } } } } ctlZoneGridView.DataCountAndBind(); ctlZoneUpdatePanel.Update(); }
/// <summary> /// Converts the supplied list of <see cref="Zone"/> objects into a list of <see cref="DbZone"/> objects. /// </summary> /// <param name="zones">The list of <see cref="Zone"/> objects to be converted.</param> /// <returns></returns> public static List <DbZone> GetDbZones(List <Zone> zones) { var dbZones = new List <DbZone>(); foreach (var zone in zones) { DbZone dbZone = GetDbZone(zone); dbZones.Add(dbZone); } return(dbZones); }
public void GetZoneInfo(DbZone zone, string mode) { TextBox ctlComment = (TextBox)ctlZoneForm.FindControl("ctlComment"); CheckBox ctlActiveChk = (CheckBox)ctlZoneForm.FindControl("ctlActiveChk"); zone.Comment = ctlComment.Text; zone.Active = ctlActiveChk.Checked; if (mode.Equals("Insert")) { zone.CreBy = UserAccount.UserID; zone.CreDate = DateTime.Now; } zone.UpdBy = UserAccount.UserID; zone.UpdDate = DateTime.Now; zone.UpdPgm = ProgramCode; }
protected void ctlZoneForm_ItemUpdating(object sender, FormViewUpdateEventArgs e) { short zoneId = UIHelper.ParseShort(ctlZoneForm.DataKey["ZoneID"].ToString()); short zoneLangId = UIHelper.ParseShort(ctlZoneForm.DataKey["ZoneLangID"].ToString()); DbZone zone = DbZoneService.FindByIdentity(zoneId); GetZoneInfo(zone, "Update"); try { DbZoneLangService.UpdateZoneLang(zone); ctlZoneGridView.DataCountAndBind(); ctlZoneForm.ChangeMode(FormViewMode.ReadOnly); CloseZonePopUp(); } catch (ServiceValidationException ex) { ValidationErrors.MergeErrors(ex.ValidationErrors); } }
public void UpdateZoneLang(DbZone zone) { Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors(); if (!errors.IsEmpty) { throw new ServiceValidationException(errors); } //DbZone dbZone = SsDbDaoProvider.DbZoneDao.FindByIdentity(zone.Zoneid); //dbZone.GroupStatus = zone.GroupStatus; //dbZone.Status = zone.Status; //dbZone.Comment = zone.Comment; //dbZone.Active = zone.Active; //dbZone.UpdBy = zone.UpdBy; //dbZone.UpdDate = DateTime.Now.Date; //dbZone.UpdPgm = zone.UpdPgm; SsDbDaoProvider.DbZoneDao.SaveOrUpdate(zone); }
/// <summary> /// Converts the supplied <see cref="Zone"/> into a <see cref="DbZone"/>. /// </summary> /// <param name="zone">The <see cref="Zone"/> to be converted.</param> /// <returns></returns> public static DbZone GetDbZone(Zone zone) { DbZone dbZone = new DbZone { GeotabId = zone.Id.ToString(), Displayed = zone.Displayed ?? false, MustIdentifyStops = zone.MustIdentifyStops ?? false, Name = zone.Name, Version = zone.Version ?? null }; if (zone.ActiveFrom != null) { dbZone.ActiveFrom = zone.ActiveFrom; } if (zone.ActiveTo != null) { dbZone.ActiveTo = zone.ActiveTo; } if (zone.CentroidLatitude != null) { dbZone.CentroidLatitude = zone.CentroidLatitude; } if (zone.CentroidLongitude != null) { dbZone.CentroidLongitude = zone.CentroidLongitude; } if (zone.Comment != null && zone.Comment.Length > 0) { dbZone.Comment = zone.Comment; } if (zone.ExternalReference != null && zone.ExternalReference.Length > 0) { dbZone.ExternalReference = zone.ExternalReference; } string zonePoints = JsonConvert.SerializeObject(zone.Points); dbZone.Points = zonePoints; return(dbZone); }
public long AddZoneLang(DbZone zone, DbZoneLang zoneLang) { Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors(); if (string.IsNullOrEmpty(zoneLang.ZoneName)) { errors.AddError("Zone.Error", new Spring.Validation.ErrorMessage("RequiredZoneName")); } //else //{ // IList<DbStatus> statusList = SsDbDaoProvider.DbStatusDao.FindByStatusCriteria(status); // if (statusList.Count != 0) // { // errors.AddError("Status.Error", new Spring.Validation.ErrorMessage("LanguageNameIsAlready")); // } //} //if (string.IsNullOrEmpty(status.Status)) //{ // errors.AddError("Status.Error", new Spring.Validation.ErrorMessage("RequiredSymbol")); //} if (!errors.IsEmpty) { throw new ServiceValidationException(errors); } //DbStatus dbstatus = new DbStatus(); //dbstatus.GroupStatus = status.GroupStatus; //dbstatus.Status = status.Status; //dbstatus.Comment = status.Comment; //dbstatus.Active = status.Active; //dbstatus.CreBy = status.CreBy; //dbstatus.CreDate = DateTime.Now.Date; //dbstatus.UpdBy = status.UpdBy; //dbstatus.UpdDate = DateTime.Now.Date; //dbstatus.UpdPgm = status.UpdPgm; SsDbDaoProvider.DbZoneDao.Save(zone); return(SsDbDaoProvider.DbZoneLangDao.Save(zoneLang)); }
/// <summary> /// Indicates whether the <see cref="DbZone"/> differs from the <see cref="Zone"/>, thereby requiring the <see cref="DbZone"/> to be updated in the database. /// </summary> /// <param name="dbZone">The <see cref="DbZone"/> to be evaluated.</param> /// <param name="zone">The <see cref="Zone"/> to compare against.</param> /// <returns></returns> public static bool DbZoneRequiresUpdate(DbZone dbZone, Zone zone) { if (dbZone.GeotabId != zone.Id.ToString()) { throw new ArgumentException($"Cannot compare Zone '{zone.Id}' with DbZone '{dbZone.GeotabId}' because the IDs do not match."); } DateTime dbZoneActiveFromUtc = dbZone.ActiveFrom.GetValueOrDefault().ToUniversalTime(); DateTime dbZoneActiveToUtc = dbZone.ActiveTo.GetValueOrDefault().ToUniversalTime(); if (dbZone.ActiveFrom != zone.ActiveFrom && dbZoneActiveFromUtc != zone.ActiveFrom) { return(true); } if (dbZone.ActiveTo != zone.ActiveTo && dbZoneActiveToUtc != zone.ActiveTo) { return(true); } if (zone.Displayed == null) { zone.Displayed = false; } if (zone.MustIdentifyStops == null) { zone.MustIdentifyStops = false; } if (dbZone.CentroidLatitude != zone.CentroidLatitude || dbZone.CentroidLongitude != zone.CentroidLongitude || dbZone.Displayed != zone.Displayed || dbZone.MustIdentifyStops != zone.MustIdentifyStops || dbZone.Version != zone.Version) { return(true); } if (dbZone.Comment != zone.Comment) { if (dbZone.Comment == null && zone.Comment == "") { return(false); } else { return(true); } } if (dbZone.ExternalReference != zone.ExternalReference) { if (dbZone.ExternalReference == null && zone.ExternalReference == "") { return(false); } else { return(true); } } if (dbZone.Name != zone.Name) { if (dbZone.Name == null && zone.Name == "") { return(false); } else { return(true); } } string zonePoints = JsonConvert.SerializeObject(zone.Points); if (dbZone.Points != zonePoints) { return(true); } return(false); }