private void mDelete(Guid iDSubject, bool loadList = true) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); try { Subjects subjects = new Subjects(iDSubject); subjects.MarkAsDeleted(false); subjects.Save(); tx.CommitTransaction(); if (loadList) { pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.deleted"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); mLoadList(); } } catch (Exception ex) { pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } }
private void mSave() { if (mValidateAddEdit()) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); bool isNew = false; try { tx.BeginTransaction(); Subjects subjects = new Subjects(); if (pIDSubject.HasValue) { subjects.LoadByPrimaryKey(pIDSubject.Value); } else { subjects.AddNew(); subjects.pPriority = mSetPriority(); pIDSubject = subjects.pIDSubject = Guid.NewGuid(); subjects.pDate = DateTime.UtcNow.AddHours(Global.MethodsAndProps.TimeZone); isNew = true; } subjects.pIDSubjectType = (byte)SubjectTypes.Enum.listItem; subjects.pIDLanguage = pLanguageID; subjects.pTitle = txtTitle.Text; HiddenField TCMEValue = (HiddenField)tinyMCE.FindControl("TCMEValue"); subjects.pBody = System.Web.HttpUtility.HtmlDecode(TCMEValue.Value); subjects.pIsActive = cbxIsActive.Checked; subjects.pIDParent = pSubjectTypeID.Value; subjects.pDate = Convert.ToDateTime(string.Format("{0} {1}", Convert.ToDateTime(txtDate.Text).ToString(Global.MethodsAndProps.DateFormat), DateTime.UtcNow.AddHours(Global.MethodsAndProps.TimeZone).ToString("HH:mm:ss"))); subjects.pAlias = Global.MethodsAndProps.mAliasCorrection(txtAlias.Text); subjects.Save(); //mUpdateSiteMap = No Need, as there is "List Name" for urls in Sitemaps if (isNew) { mSetPopupData(subjects); } tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } else { mShowMessage(pMessage); } }
private void mSave() { if (mValidateAddEdit()) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); bool isNew = false; try { tx.BeginTransaction(); Subjects subjects = new Subjects(); if (pIDSubject.HasValue) { subjects.LoadByPrimaryKey(pIDSubject.Value); } else { subjects.AddNew(); subjects.pPriority = mSetPriority(); pIDSubject = subjects.pIDSubject = Guid.NewGuid(); subjects.pDate = DateTime.UtcNow.AddHours(Global.MethodsAndProps.TimeZone); isNew = true; } subjects.pIDSubjectType = (byte)SubjectTypes.Enum.category; subjects.pIDLanguage = pLanguageID; subjects.pTitle = txtTitle.Text; HiddenField TCMEValue = (HiddenField)tinyMCE.FindControl("TCMEValue"); subjects.pBody = System.Web.HttpUtility.HtmlDecode(TCMEValue.Value); subjects.pIsActive = true; //subjects.pIDParent = Not applicable. subjects.pAlias = Global.MethodsAndProps.mAliasCorrection(txtAlias.Text); subjects.Save(); if (isNew) { mSetPopupData(subjects); } tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } else { mShowMessage(pMessage); } }
private void mSave() { if (mValidateAddEdit()) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); bool isNew = false; try { tx.BeginTransaction(); Subjects subjects = new Subjects(); subjects.LoadBySubjectAliasAndIDSubjectType(pIDUser.Value.ToString(), (byte)SubjectTypes.Enum.userPage); if (subjects.RowCount > 0) { // Do Nothing, It's an Edit action } else { subjects.AddNew(); subjects.pIDSubject = Guid.NewGuid(); subjects.pDate = DateTime.UtcNow.AddHours(Global.MethodsAndProps.TimeZone); isNew = true; } subjects.pIDSubjectType = (byte)SubjectTypes.Enum.userPage; subjects.pIDLanguage = pLanguageID; subjects.pTitle = txtTitle.Text; HiddenField TCMEValue = (HiddenField)tinyMCE.FindControl("TCMEValue"); subjects.pBody = System.Web.HttpUtility.HtmlDecode(TCMEValue.Value); subjects.pIsActive = cbxIsActive.Checked; subjects.pAlias = pIDUser.ToString(); subjects.SetColumnNull(Subjects.ColumnNames.IDParent); subjects.Save(); if(isNew) mSetPopupData(subjects); tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } else { mShowMessage(pMessage); } }
private void mSave() { if (mValidateAddEdit()) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); try { tx.BeginTransaction(); Medias media = new Medias(); if (pIDMedia.HasValue) { media.LoadByPrimaryKey(pIDMedia.Value); } else { media.AddNew(); } media.pFileName = txtFileName.Text; media.pFileExtention = pFileExtension; //HiddenField TCMEValue = (HiddenField)tinyMCE.FindControl("TCMEValue"); //media.pDescription = System.Web.HttpUtility.HtmlDecode(TCMEValue.Value); media.pDescription = txtDescription.Text; media.pDate = Convert.ToDateTime(string.Format("{0} {1}", Convert.ToDateTime(txtDate.Text).ToString(Global.MethodsAndProps.DateFormat), DateTime.UtcNow.AddHours(Global.MethodsAndProps.TimeZone).ToString("HH:mm:ss"))); media.pUrl = txtUrl.Text; media.Save(); mSaveMediaFile(media.pIDMedia.ToString()); tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); if (!pIDMedia.HasValue) { mClear(); } } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } else { mShowMessage(pMessage); } }
private void mDelete(string pIDDepartment, bool loadList = true) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); Languages lang = new Languages(pLanguageID); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath(string.Format("{0}{1}.xml", Global.Constants.FOLDER_CONTACTS, lang.pCode))); XmlNode root = xmlDoc.DocumentElement; XmlNode departmentNode = null; departmentNode = root.SelectSingleNode(string.Format("//Departments/Department[@id='{0}']", pIDDepartment)); if (!string.IsNullOrEmpty(pIDDepartment)) { int count = xmlDoc.SelectNodes("Departments/Department").Count; try { tx.BeginTransaction(); if (count < 2) { File.Delete(Server.MapPath(string.Format("{0}{1}.xml", Global.Constants.FOLDER_CONTACTS, lang.pCode))); } else { departmentNode.ParentNode.RemoveChild(departmentNode); xmlDoc.Save(Server.MapPath(string.Format("{0}{1}.xml", Global.Constants.FOLDER_CONTACTS, lang.pCode))); } tx.CommitTransaction(); if (loadList) { pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.deleted"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); mLoadList(); } } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } }
/// <summary> /// This must be called after RollbackTransaction or no futher database activity will happen successfully on the current thread. /// </summary> public static void ThreadTransactionMgrReset() { TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr(); try { if (txMgr.txCount > 0 && txMgr.hasRolledBack == false) { txMgr.RollbackTransaction(); } } catch { } Thread.SetData(txMgrSlot, null); }
private void mSave() { if (mValidateAddEdit()) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); try { tx.BeginTransaction(); XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(translateFile)); XmlNode root = doc.DocumentElement; XmlNode messageNode = root.SelectSingleNode(string.Format("//message[@key='{0}']", ddlModules.SelectedItem.Value)); Table tblModuleDetails = (Table)uplAddEdit.FindControl("tblModuleDetails"); foreach (TableRow row in tblModuleDetails.Rows) { foreach (TableCell cell in row.Cells) { foreach (Control tb in cell.Controls) { if (tb is TextBox) { messageNode = root.SelectSingleNode(string.Format("//message[@key='{0}']", ((TextBox)tb).ID)); messageNode.InnerText = ((TextBox)tb).Text; } } } } doc.Save(Server.MapPath(translateFile)); tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } else { mShowMessage(pMessage); } }
private void mDelete(Guid iDSubject, bool loadList = true) { if (mValidateDelete(iDSubject)) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); try { tx.BeginTransaction(); MediaSubjects mediaSubjects = new MediaSubjects(); mediaSubjects.LoadByIDSubject(iDSubject); mediaSubjects.DeleteAll(); mediaSubjects.Save(); SubjectPlugins subjectPlugin = new SubjectPlugins(); subjectPlugin.LoadByIDSubject(iDSubject); subjectPlugin.DeleteAll(); subjectPlugin.Save(); GalleryPlugins GalleryPlugins = new GalleryPlugins(); GalleryPlugins.LoadByIDSubject(iDSubject); GalleryPlugins.DeleteAll(); GalleryPlugins.Save(); Subjects subject = new Subjects(iDSubject); subject.MarkAsDeleted(false); subject.Save(); tx.CommitTransaction(); if (loadList) { pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.deleted"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); mLoadList(); } } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); } } mShowMessage(pMessage); }
private void mDelete(Guid iDUser) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); try { Subjects subjects = new Subjects(); subjects.LoadBySubjectAliasAndIDSubjectType(pIDUser.Value.ToString(), (byte)SubjectTypes.Enum.userPage); if (subjects.RowCount > 0) { tx.BeginTransaction(); MediaSubjects mediaSubjects = new MediaSubjects(); mediaSubjects.LoadByIDSubject(subjects.pIDSubject); mediaSubjects.DeleteAll(); mediaSubjects.Save(); SubjectPlugins subjectPlugin = new SubjectPlugins(); subjectPlugin.LoadByIDSubject(subjects.pIDSubject); subjectPlugin.DeleteAll(); subjectPlugin.Save(); GalleryPlugins GalleryPlugins = new GalleryPlugins(); GalleryPlugins.LoadByIDSubject(subjects.pIDSubject); GalleryPlugins.DeleteAll(); GalleryPlugins.Save(); Subjects subject = new Subjects(subjects.pIDSubject); subject.MarkAsDeleted(false); subject.Save(); tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.deleted"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); mLoadList(); } } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } }
/// <summary> /// This static method is how you obtain a reference to the TransactionMgr. You cannot call "new" on TransactionMgr. /// If a TransactionMgr doesn't exist on the current thread, one is created and returned to you. /// </summary> /// <returns>The one and only TransactionMgr for this thread.</returns> public static TransactionMgr ThreadTransactionMgr() { TransactionMgr txMgr = null; object obj = Thread.GetData(txMgrSlot); if (obj != null) { txMgr = (TransactionMgr)obj; } else { txMgr = new TransactionMgr(); Thread.SetData(txMgrSlot, txMgr); } return(txMgr); }
/// <summary> /// Execute the Query and loads your CoreEntity. /// You can pass in the conjustion that will be used between the WHERE parameters, either, "AND" or "OR". "AND" is the default. /// Also, if you need to be notified that this is being called override CoreEntity.OnQueryLoad(). /// </summary> /// <returns>True if at least one record was loaded</returns> public bool Load(string conjuction) { bool loaded = false; DataTable dt = null; try { if ((_aggregateParameters == null || _aggregateParameters.Count <= 0) && _resultColumns.Length <= 0 && _countAll == false) { this._entity._canSave = true; } this._entity.OnQueryLoad(conjuction); IDbCommand cmd = _Load(conjuction); _lastQuery = cmd.CommandText; IDbDataAdapter da = this._entity.CreateIDbDataAdapter(); da.SelectCommand = cmd; TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr(); dt = new DataTable(_entity.MappingName); txMgr.Enlist(cmd, _entity); DbDataAdapter dbDataAdapter = this._entity.ConvertIDbDataAdapter(da); dbDataAdapter.Fill(dt); txMgr.DeEnlist(cmd, _entity); } catch (Exception ex) { throw ex; } finally { this._entity.DataTable = dt; loaded = (dt.Rows.Count > 0); } return(loaded); }
private void mSave() { if (mValidateAddEdit()) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); bool isNew = false; try { tx.BeginTransaction(); Subjects subjects = new Subjects(); if (pIDSubject.HasValue) { subjects.LoadByPrimaryKey(pIDSubject.Value); } else { subjects.AddNew(); subjects.pPriority = mSetPriority(); pIDSubject = subjects.pIDSubject = Guid.NewGuid(); subjects.pDate = DateTime.UtcNow.AddHours(Global.MethodsAndProps.TimeZone); isNew = true; } subjects.pIDSubjectType = Convert.ToByte(ddlAddEditGalleryType.SelectedValue); subjects.pIDLanguage = pLanguageID; subjects.pTitle = txtTitle.Text; HiddenField TCMEValue = (HiddenField)tinyMCE.FindControl("TCMEValue"); subjects.pBody = System.Web.HttpUtility.HtmlDecode(TCMEValue.Value); subjects.pIsActive = cbxIsActive.Checked; if (ddlCategory.SelectedIndex != 0) { subjects.pIDParent = new Guid(ddlCategory.SelectedValue); } else { subjects.SetColumnNull(Subjects.ColumnNames.IDParent); } subjects.pAlias = Global.MethodsAndProps.mAliasCorrection(txtAlias.Text); subjects.Save(); if (pIDSubject.HasValue) { Global.MethodsAndProps.mUpdateSiteMap(subjects.pIDSubject.ToString(), subjects.pAlias, Global.Constants.STRING_GALLERY_MODULE); } if (isNew) { mSetPopupData(subjects); } tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } else { mShowMessage(pMessage); } }
private void mSave() { if (mValidateAddEdit()) { DAL.GlobalCore.TransactionMgr tx = DAL.GlobalCore.TransactionMgr.ThreadTransactionMgr(); try { tx.BeginTransaction(); Languages lang = new Languages(pLanguageID); string xmlMapPath = Server.MapPath(string.Format("{0}{1}.xml", Global.Constants.FOLDER_CONTACTS, lang.pCode)); if (!File.Exists(xmlMapPath)) { mCreateXML(xmlMapPath); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlMapPath); XmlNode root = xmlDoc.DocumentElement; XmlNode departmentNode = null; if (!string.IsNullOrEmpty(pIDDepartment)) { departmentNode = root.SelectSingleNode(string.Format("//Departments/Department[@id='{0}']", pIDDepartment)); departmentNode.SelectSingleNode("title").InnerText = txtTitle.Text; departmentNode.SelectSingleNode("subject").InnerText = txtSubject.Text; departmentNode.SelectSingleNode("email").InnerText = txtEmail.Text; departmentNode.SelectSingleNode("phone").InnerText = txtPhone.Text; departmentNode.SelectSingleNode("fax").InnerText = txtFax.Text; departmentNode.SelectSingleNode("address").InnerText = txtAddress.Text; } else { int newID = 1; if (root.LastChild != null) { departmentNode = root.LastChild; newID = Convert.ToInt32(departmentNode.Attributes["id"].Value) + 1; } XmlElement DepartmentNode = xmlDoc.CreateElement("Department"); XmlElement DepartmentTitle = xmlDoc.CreateElement("title"); XmlElement DepartmentSubject = xmlDoc.CreateElement("subject"); XmlElement DepartmentEmail = xmlDoc.CreateElement("email"); XmlElement DepartmentPhone = xmlDoc.CreateElement("phone"); XmlElement DepartmentFax = xmlDoc.CreateElement("fax"); XmlElement DepartmentAddress = xmlDoc.CreateElement("address"); XmlAttribute DepartmentIdAttr = xmlDoc.CreateAttribute("id"); DepartmentIdAttr.Value = newID.ToString(); DepartmentTitle.InnerText = txtTitle.Text; DepartmentSubject.InnerText = txtSubject.Text; DepartmentEmail.InnerText = txtEmail.Text; DepartmentPhone.InnerText = txtPhone.Text; DepartmentFax.InnerText = txtFax.Text; DepartmentAddress.InnerText = txtAddress.Text; DepartmentNode.Attributes.Append(DepartmentIdAttr); DepartmentNode.AppendChild(DepartmentTitle); DepartmentNode.AppendChild(DepartmentSubject); DepartmentNode.AppendChild(DepartmentEmail); DepartmentNode.AppendChild(DepartmentPhone); DepartmentNode.AppendChild(DepartmentFax); DepartmentNode.AppendChild(DepartmentAddress); root.AppendChild(DepartmentNode); } xmlDoc.Save(Server.MapPath(string.Format("{0}{1}.xml", Global.Constants.FOLDER_CONTACTS, lang.pCode))); mLoadAll(); tx.CommitTransaction(); pMessage.Clear(); pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success); mShowMessage(pMessage); } catch (Exception ex) { tx.RollbackTransaction(); pMessage.Clear(); pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error); mShowMessage(pMessage); } } else { mShowMessage(pMessage); } }