public static void Commit(LangValue langValueActive, LangValue langValueUnCommitted) { SqlConnection sqlConn = new SqlConnection(_BaseDB.ConnectionString()); sqlConn.Open(); SqlTransaction sqlTrans = sqlConn.BeginTransaction(); try { // move the active version to the archive Archive(sqlTrans, langValueActive); Delete(sqlTrans, langValueActive); // mark and save the uncommited version as active. langValueUnCommitted.Active = true; Save(sqlTrans, langValueUnCommitted); sqlTrans.Commit(); } catch (Exception ex) { langValueUnCommitted.Active = false; sqlTrans.Rollback(); throw ex; } finally { sqlConn.Close(); } }
public static LangValue Load(int langID, int langInterfaceID, int langResourceID, bool active) { //-- Select, Params, Execute SQL string connectionString = _BaseDB.ConnectionString(); SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@LangID", langID), new SqlParameter("@LangInterfaceID", langInterfaceID), new SqlParameter("@LangResourceID", langResourceID), new SqlParameter("@Active", active) }; string sqlSelect = @"SELECT " + SqlSelectList() + @" FROM tblLangValue WHERE LangID = @LangID AND LangInterfaceID = @LangInterfaceID AND LangResourceID = @LangResourceID AND Active = @Active " ; DataTable dt = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlSelect, sqlParams).Tables[0]; //-- Lang Object LangValue langValue = new LangValue(); if (dt.Rows.Count > 0) { langValue = LoadMapping(dt.Rows[0]); } return(langValue); }
//-- Load list of active or inactive langValues public static ArrayList LoadList(int langID, int langInterfaceID, bool active) { //-- Select, Params, Execute SQL string connectionString = _BaseDB.ConnectionString(); SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@LangID", langID), new SqlParameter("@LangInterfaceID", langInterfaceID), new SqlParameter("@active", active) }; string sqlSelectList = @"SELECT " + SqlSelectList() + @" FROM tblLangValue WHERE LangID = @LangID " ; if (langInterfaceID > 0) { sqlSelectList += @" AND LangInterfaceID = @LangInterfaceID"; } sqlSelectList += " AND Active = @Active "; DataTable dt = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlSelectList, sqlParams).Tables[0]; //-- Load Array List ArrayList list = new ArrayList(); foreach (DataRow dr in dt.Rows) { LangValue langValue = LoadMapping(dr); list.Add(langValue); } return(list); }
//-- Save public static void Save(LangValue langValue) { SqlConnection sqlConn = new SqlConnection(_BaseDB.ConnectionString()); sqlConn.Open(); SqlTransaction sqlTrans = sqlConn.BeginTransaction(); try { if (langValue.LangID == 0 || langValue.LangInterfaceID == 0 || langValue.LangResourceID == 0) { throw new ApplicationException("Language, Interface and Resource are required fields"); } Save(sqlTrans, langValue); sqlTrans.Commit(); } catch (Exception ex) { sqlTrans.Rollback(); throw ex; } finally { sqlConn.Close(); } }
private static void Delete(SqlTransaction sqlTrans, LangValue langValue) { SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@LangValueID", langValue.RecordID) }; string sqlDelete = @"DELETE FROM tblLangValue WHERE LangValueID = @LangValueID"; SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.Text, sqlDelete, sqlParams); }
internal static void Commit(int userID, LangValue langValueUnCommitted) { langValueUnCommitted.UserID = userID; //-- Find committed version if it exists. LangValue langValueActive = LangValueDB.Load(langValueUnCommitted.LangID, langValueUnCommitted.LangInterfaceID, langValueUnCommitted.LangResourceID, true); langValueActive.UserID = userID; LangValueDB.Commit(langValueActive, langValueUnCommitted); }
private static void Archive(SqlTransaction sqlTrans, LangValue langValue) { SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@LangID", langValue.LangID), new SqlParameter("@LangInterfaceID", langValue.LangInterfaceID), new SqlParameter("@LangResourceID", langValue.LangResourceID), new SqlParameter("@LangEntryValue", langValue.LangEntryValue), new SqlParameter("@UserCreated", langValue.UserID) }; string sqlInsert = @"INSERT INTO tblLangValueArchive(LangID, LangInterfaceID, LangResourceID, LangEntryValue, UserCreated) VALUES(@LangID, @LangInterfaceID, @LangResourceID, @LangEntryValue, @UserCreated)"; SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.Text, sqlInsert, sqlParams); }
private void rptFlag_ItemCreated(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { LangValue langValue = (LangValue)e.Item.DataItem; ImageButton imgFlag = (ImageButton)e.Item.FindControl("imgFlag"); imgFlag.ImageUrl = "/General/Images/Flags/" + langValue.LangCode + ".jpg"; imgFlag.AlternateText = langValue.LangEntryValue; imgFlag.CommandArgument = langValue.LangCode; imgFlag.Command += new CommandEventHandler(imgFlag_Command); } }
private static LangValue LoadMapping(DataRow dr) { LangValue langValue = new LangValue(); langValue.RecordID = (int)dr["LangValueID"]; langValue.langID = (int)dr["LangID"]; langValue.langInterfaceID = (int)dr["LangInterfaceID"]; langValue.langResourceID = (int)dr["LangResourceID"]; langValue.LangEntryValue = (string)dr["LangEntryValue"]; langValue.Active = (bool)dr["Active"]; _BaseDB.LoadMapping(langValue, dr); return(langValue); }
private void grdResourceList_UpdateCommand(object source, DataGridCommandEventArgs e) { int resourceID = Int32.Parse(grdResourceList.DataKeys[e.Item.ItemIndex].ToString()); int otherLangValueID = Int32.Parse(((Label)e.Item.FindControl("lblOtherLangValueID")).Text); Label lblRecordLock = (Label)e.Item.FindControl("lblRecordLock"); TextBox txtOtherValue = (TextBox)e.Item.FindControl("txtOtherValue"); //-- Get existing langvalue or create a new one (one doesn't exist for the language being entered) LangValue langValue = new LangValue(); if (otherLangValueID > 0) { langValue = LangValueAPI.GetEntity(otherLangValueID); langValue.RecordLock = new Guid(lblRecordLock.Text); } else { langValue.LangID = this.LangID; langValue.LangInterfaceID = this.LangInterfaceID; langValue.LangResourceID = resourceID; langValue.UserID = UserContext.UserID; } langValue.LangEntryValue = txtOtherValue.Text; try { LangValueAPI.Save(langValue); foreach (DictionaryEntry item in Cache) { Cache.Remove(item.Key.ToString()); } } catch (ApplicationException ex) { lblMessage.Text = ex.Message; lblMessage.CssClass = "WarningMessage"; } catch { throw; } grdResourceList.EditItemIndex = -1; Response.Redirect("Resource.aspx?langID=" + this.LangID.ToString() + "&langInterfaceID=" + this.LangInterfaceID.ToString()); }
private void grdResourceList_ItemCreated(object sender, DataGridItemEventArgs e) { //-- Get values to be used for both item and edti templates LangValue otherLangValue = new LangValue(); int resourceID = 0; if (e.Item.ItemType == ListItemType.EditItem || e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { resourceID = Int32.Parse(grdResourceList.DataKeys[e.Item.ItemIndex].ToString()); otherLangValue = ItemCreated(resourceID); } //-- Edit template: Apply to controls if (e.Item.ItemType == ListItemType.EditItem) { Label lblOtherLangValueID = (Label)e.Item.FindControl("lblOtherLangValueID"); lblOtherLangValueID.Text = otherLangValue.RecordID.ToString(); TextBox txtOtherValue = (TextBox)e.Item.FindControl("txtOtherValue"); //-- Encode so characters like <BR /> appear. txtOtherValue.Text = otherLangValue.LangEntryValue; Label lblRecordLock = (Label)e.Item.FindControl("lblRecordLock"); lblRecordLock.Text = otherLangValue.RecordLock.ToString(); Label lblCommit = (Label)e.Item.FindControl("lblCommit"); lblCommit.Visible = (otherLangValue.Active == false); } //-- Item template: Apply to controls if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label lbl = (Label)e.Item.FindControl("lblOtherValue"); lbl.Text = System.Web.HttpUtility.HtmlEncode(otherLangValue.LangEntryValue); LinkButton lnkCommit = (LinkButton)e.Item.FindControl("lnkCommit"); lnkCommit.Visible = (otherLangValue.Active == false && otherLangValue.LangID != 0); lnkCommit.CommandName = "COMMIT"; lnkCommit.Attributes.Add("onclick", "return confirm('Commit change for this resource?');"); } }
public static ArrayList LoadFlagList(bool active) { //-- Select, Params, Execute SQL string connectionString = _BaseDB.ConnectionString(); SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@active", active) }; string sqlSelectList = @"SELECT tblLang.LangCode, " + SqlSelectList() + @" FROM tblLangInterface INNER JOIN tblLangValue ON tblLangInterface.LangInterfaceID = tblLangValue.LangInterfaceID INNER JOIN tblLangResource ON tblLangValue.LangResourceID = tblLangResource.LangResourceID INNER JOIN tblLang ON tblLangResource.LangResourceName = tblLang.LangCode AND tblLangValue.LangID = tblLang.LangID WHERE (tblLangInterface.LangInterfaceName = 'LanguageNames') " ; if (active) { sqlSelectList += " AND (tblLangValue.Active = 1)"; sqlSelectList += " AND (tblLang.ShowUser = 1)"; } else { sqlSelectList += " AND (tblLang.ShowAdmin = 1)"; } sqlSelectList += " ORDER BY tblLangValue.Active, tblLang.LangName"; DataTable dt = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlSelectList, sqlParams).Tables[0]; //-- Load Array List ArrayList list = new ArrayList(); foreach (DataRow dr in dt.Rows) { LangValue langValue = LoadMapping(dr); langValue.LangCode = dr["LangCode"].ToString(); list.Add(langValue); } return(list); }
/// <summary> Save the LangValue, if the object is active, make it inactive and set ID to zero, a new record will be created.</summary> internal static void Save(LangValue langValue) { //-- if the current one is active, we will create a new record. if (langValue.Active) { langValue.RecordID = 0; langValue.Active = false; } try { LangValueDB.Save(langValue); } catch (SqlException ex) { if (ex.Number == 2627) { throw new ApplicationException("This record has already been edited. Ensure the record was not edited by another person or yourself in another browser. Please try again."); } } }
private static void Save(SqlTransaction sqlTrans, LangValue langValue) { //-- Record locked? _BaseDB.RecordLocked(sqlTrans, langValue); //-- For Date:Created,Modified,Deleted DateTime eventDate = DateTime.Now.ToUniversalTime(); Guid newRecordLock = Guid.NewGuid(); //-- Params and Sql statements // SqlParameter sqlLangEntryValue = new SqlParameter("@LangEntryValue", SqlDbType.NText); // sqlLangEntryValue.Value = langValue.LangEntryValue; SqlParameter[] sqlParams = { new SqlParameter("@LangValueID", langValue.RecordID) , new SqlParameter("@LangID", langValue.LangID) , new SqlParameter("@LangInterfaceID", langValue.LangInterfaceID) , new SqlParameter("@LangResourceID", langValue.LangResourceID) , new SqlParameter("@LangEntryValue", langValue.LangEntryValue) , new SqlParameter("@Active", langValue.Active) , new SqlParameter("@_EventUser", langValue.UserID) , new SqlParameter("@_EventDate", eventDate) , new SqlParameter("@_NewRecordLock", newRecordLock) }; string sqlInsert = @"INSERT INTO tblLangValue (LangID, LangInterfaceID, LangResourceID, LangEntryValue, Active, UserCreated, DateCreated, RecordLock) VALUES(@LangID, @LangInterfaceID, @LangResourceID, @LangEntryValue, @Active, @_EventUser, @_EventDate, @_NewRecordLock); SELECT @@IDENTITY AS [@@IDENTITY] " ; string sqlUpdate = @"UPDATE tblLangValue set LangID = @LangID , LangInterfaceID = @LangInterfaceID , LangResourceID = @LangResourceID , LangEntryValue = @LangEntryValue , Active = @Active , UserModified = @_EventUser , DateModified = @_EventDate , RecordLock = @_NewRecordLock WHERE LangValueID = @LangValueID " ; //-- Execute SQL and set object properties if (langValue.RecordID == 0) { langValue.RecordID = Int32.Parse(SqlHelper.ExecuteDataset(sqlTrans, CommandType.Text, sqlInsert, sqlParams).Tables[0].Rows[0][0].ToString()); langValue.userCreated = langValue.UserID; langValue.dateCreated = eventDate; } else { SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.Text, sqlUpdate, sqlParams); langValue.userModified = langValue.UserID; langValue.dateModified = eventDate; } langValue.RecordLock = newRecordLock; }
public static LangValue GetEntity(int langValueID) { LangValue langValue = LangValueDB.Load(langValueID); return(langValue); }
public static void Save(LangValue langValue) { LangValueBUS.Save(langValue); }
public static void Commit(int userID, int langID, int langInterfaceID, int langResourceID) { LangValue unCommitted = LangValueDB.Load(langID, langInterfaceID, langResourceID, false); LangValueBUS.Commit(userID, unCommitted); }