public DataSet ExecuteDataset(string spName, params object[] parameterValues) { DataSet ds = new DataSet(); if (IsOffline) { CacheDataGet(ds, spName + ParamList(parameterValues), true); } else { if (UseService) { parameterValues = FixParameters(parameterValues); ds = BEManager.DecompressDataSet(AtriumX().ExecuteDatasetByte(AtriumXCon, spName, parameterValues), ds); } else { ds = BEManager.DecompressDataSet(this.DAL.ExecuteDatasetByte(spName, parameterValues), ds); } if (AllowOffline) { CacheDataSet(ds, spName + ParamList(parameterValues)); } } return(ds); }
/// <summary> /// Constructor for class /// </summary> /// <param name="mngr">The manager for this object</param> /// <param name="pDT">The datatable that will be managed</param> public ObjectBE(BEManager mngr, DataTable pDT) { myMngr = mngr; myEntityName = pDT.TableName; myDT = pDT; Init(); myUser = mngr.AppMan.myUser; myMngr.myBEs.Add(myEntityName, this); }
public ObjectBE(BEManager mngr, DataTable pDT, string entityName) { myMngr = mngr; myEntityName = entityName; myDT = pDT.Clone(); myDT.TableName = entityName; myMngr.MyDS.Tables.Add(myDT); Init(); myUser = mngr.AppMan.myUser; myMngr.myBEs.Add(entityName, this); }
/// <summary> /// Loads all the records for this table from the database /// </summary> public void Load() { DataTable dt = myDT.Clone(); if (myMngr.AppMan.UseService) { Fill(BEManager.DecompressDataTable(myMngr.AppMan.AtriumX().Load(myDT.TableName, myMngr.AppMan.AtriumXCon), dt)); } else { try { Fill(BEManager.DecompressDataTable(myODAL.LoadByte(), dt)); } catch (System.Runtime.Serialization.SerializationException x) { RecoverDAL(); Fill(BEManager.DecompressDataTable(myODAL.LoadByte(), dt)); } } }
/// <summary> /// Merges the compressed datatable returned from the DAL into the managed datatable /// </summary> /// <param name="b"></param> /// <returns></returns> public int Fill(byte[] b) { //System.Diagnostics.Trace.WriteLine(this.GetType().ToString(), "FillDTByte"); DataTable dt = BEManager.DecompressDataTable(b, myDT); return(Fill(dt)); //int i = dt.Rows.Count; //if (dt.Rows.Count > 0) //{ // isFilling = true; // lock (thisLock) // { // this.myDT.BeginLoadData(); // this.myDT.Merge(dt, false, MissingSchemaAction.Ignore); // this.myDT.EndLoadData(); // } // isFilling = false; //} //return i; }
private void Update(string address) { ObjectBE[] copy = updateList.ToArray(); updateList.Clear(); foreach (ObjectBE obe in copy) { try { obe.BeforeUpdate(); } catch (Exception x1) { throw new AtriumException("Update stopped on " + obe.myDT.TableName + ". Reject changes will restore Datatables consistency with database.\r\n", x1); } if (obe.myDT.HasErrors) { throw new AtriumException("Update stopped on " + obe.myDT.TableName + ". Reject changes will restore Datatables consistency with database.\r\n" + obe.ErrorsForTable(obe.myDT)); } } string tableNm = ""; System.Data.DataSet dsDown = null; try { System.Data.DataSet dsUp = new System.Data.DataSet(); List <string> tables = new List <string>(); foreach (ObjectBE obe in copy) { System.Data.DataTable dt = obe.myDT.GetChanges(); if (dt != null) { dt.ExtendedProperties.Remove("BE"); if (!obe.IsVirtual) { //extend this scheme to include the obe.MyMNg.CurrentFileid //this way we can put the returned datatable into the right obe object //we will need to rename the datatables in the server code to include this info if (obe.DALName == "") { tables.Add(dt.TableName); } else { tables.Add(dt.TableName + "." + obe.DALName); } } if (!dsUp.Tables.Contains(dt.TableName)) { //TFS#51279 CJW 2013-8-30 - Deal with time zone off sets set by web service foreach (System.Data.DataColumn column in dt.Columns) { if (column.DataType == typeof(DateTime)) { //column.DateTimeMode = System.Data.DataSetDateTime.Unspecified; } } //End TFS #51279 dsUp.Tables.Add(dt); } } } if (myMng.AppMan.Compression) //compression on { byte[] byteUp = BEManager.CompressData(dsUp); //dsUp.Dispose(); //dsUp = null; dsUp.Clear(); dsUp.AcceptChanges(); if (!myMng.AppMan.UseService) { byteUp = this.myMng.DAL.Update(tables, byteUp); } else { byteUp = myMng.AppMan.AtriumX().UpdateComp(myMng.AppMan.Connect, myMng.AppMan.myPwd, myMng.AppMan.myUser, tables.ToArray(), byteUp); } dsDown = BEManager.DecompressDataSet(byteUp, dsUp); } else //compression ffn { if (!myMng.AppMan.UseService) { dsDown = this.myMng.DAL.Update(tables, dsUp); } else { dsUp.RemotingFormat = System.Data.SerializationFormat.Binary; dsDown = myMng.AppMan.AtriumX().Update(myMng.AppMan.Connect, myMng.AppMan.myPwd, myMng.AppMan.myUser, tables.ToArray(), dsUp); } } } catch (Exception x) { if (x.InnerException != null) { if (x.InnerException.GetType() == typeof(System.Data.SqlClient.SqlException)) { System.Data.SqlClient.SqlException sqle = (System.Data.SqlClient.SqlException)x.InnerException; switch (sqle.Number) { case 2601: throw new Exception(Properties.Resources.DuplicateValueInAUniqueColumn, sqle); case 50000: throw new AtriumException(sqle.Message); default: throw sqle; } } else if (x.InnerException.GetType() == typeof(System.Data.DBConcurrencyException)) { System.Data.DBConcurrencyException dbce = (System.Data.DBConcurrencyException)x.InnerException; throw new ConcurrencyException(String.Format(Properties.Resources.ConcurrencyError, ""), x); } else { throw x; } } else { throw new UpdateFailedException("Update failed on " + tableNm + ". Datatables need to be reloaded as acceptchanges/merge has been called on them.\r\n", x); } } //TFS#51508 CJW 2013-09-19 //all updates have succeeded //merge data back into client datasets //and accept changes bool isError = false; Exception x5 = null; foreach (ObjectBE obe in copy) { tableNm = obe.myDT.TableName; if (dsDown.Tables.Count > 0 && dsDown.Tables.Contains(tableNm)) { try { //hack required because we remove the Contents column on the server to speed up the download //if we leave it in it gets blanked if (tableNm.ToLower() == "doccontent") { dsDown.Tables[tableNm].Columns.Remove("Contents"); }//end of hack if (!obe.IsVirtual) { obe.Fill(dsDown.Tables[tableNm]); } obe.AfterUpdate(); } catch (System.InvalidOperationException x) { //trap for Corrupt datatable index '5' isError = true; x5 = x; } //acceptchanges must be called last so that afterupdate knows which rows o process obe.myDT.AcceptChanges(); } } if (isError) { throw new AtriumException("An unexpected error has occurred. Please close and restart Atrium.", x5); } }
public BusinessProcess(BEManager mng) { myMng = mng; }
public void Populate(appDB.ddTableRow drTable) { DataTable dtTyped = null; try { atLogic.BEManager mngr = myA.GetFile(0).GetBEMngrForTable(drTable.DBTableName); dtTyped = mngr.MyDS.Tables[drTable.DBTableName]; } catch (Exception x) { //ignore } DataTable dtViews = myA.GetGeneralRec("select * from information_schema.columns where table_schema='dbo' and table_name='v" + drTable.DBTableName + "' "); DataTable dtTable = myA.GetGeneralRec("select * from information_schema.columns where table_schema='dbo' and table_name='" + drTable.DBTableName + "' "); if (dtTable.Rows.Count == 0) { drTable.isDBTable = false; } else { drTable.isDBTable = true; } if (dtTyped != null) { foreach (DataColumn dc in dtTyped.Columns) { appDB.ddFieldRow drField; if (myA.DB.ddField.Select("Tableid=" + drTable.TableId.ToString() + " and DBFieldName='" + dc.ColumnName + "'").Length == 0) { drField = (appDB.ddFieldRow)Add(drTable); drField.FieldName = dc.ColumnName; drField.DBFieldName = dc.ColumnName; if (drTable.isDynamic) { drField.AllowInRelatedFields = false; } } else { drField = (appDB.ddFieldRow)myA.DB.ddField.Select("Tableid=" + drTable.TableId.ToString() + " and DBFieldName='" + dc.ColumnName + "'")[0]; } drField.isMissing = true; drField.DataType = dc.DataType.Name; if (drField.IsLeftEngNull()) { drField.LeftEng = SplitCamelCase(drField.FieldName); drField.LeftFre = SplitCamelCase(drField.FieldName); } if (dtViews.Select("Column_name='" + dc.ColumnName + "'", "").Length == 0) { drField.isVirtualColumn = true; } else { drField.isMissing = false; drField.isVirtualColumn = false; } if (!drField.isVirtualColumn && dtTable.Select("Column_name='" + dc.ColumnName + "'", "").Length == 0) { drField.isFromView = true; } else { drField.isMissing = false; drField.isFromView = false; } } //check for "obsolete" columns foreach (appDB.ddFieldRow drf in drTable.GetddFieldRows()) { if (!dtTyped.Columns.Contains(drf.DBFieldName)) { drf.AllowInRelatedFields = false; drf.DescEng = "OBSOLETE"; } } } else { foreach (DataRow dr in dtViews.Rows) { if (myA.DB.ddField.Select("Tableid=" + drTable.TableId.ToString() + " and DBFieldName='" + dr["Column_name"].ToString() + "'").Length == 0) { appDB.ddFieldRow drField = (appDB.ddFieldRow)Add(drTable); drField.FieldName = dr["Column_name"].ToString(); if (dtTable.Select("Column_name='" + drField.FieldName + "'", "").Length == 0) { drField.isFromView = true; drField.isMissing = false; } } } } }
//atriumDB.ContactDataTable myContactDT; protected ContactBE(atLogic.BEManager pBEMng, DataTable pdt) : base(pBEMng, pdt) { myA = pBEMng; init(pdt); }
// Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. private void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this.isDisposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { OnUpdate = null; // Dispose managed resources. //myODAL.Dispose(); //if (pulse != null) //{ // if (pulse!=null) pulse.Elapsed -= pulseHndl; // if (pulse != null) pulse.Stop(); // if (pulse != null) pulse.Enabled = false; // if (pulse != null) pulse.Dispose(); // pulse = null; //} if (myDT != null) { //disconnect all events if (myDT != null) { myDT.RowChanging -= new DataRowChangeEventHandler(RowChangingEventHandler); } if (myDT != null) { myDT.RowChanged -= new DataRowChangeEventHandler(RowChangedEventHandler); } if (myDT != null) { myDT.RowDeleting -= new DataRowChangeEventHandler(RowChangingEventHandler); } if (myDT != null) { myDT.RowDeleted -= new DataRowChangeEventHandler(RowChangedEventHandler); } if (this.IsColumnChangeMode) { if (myDT != null) { myDT.ColumnChanging -= new DataColumnChangeEventHandler(ColumnChangingEventHandler); } if (myDT != null) { myDT.ColumnChanged -= new DataColumnChangeEventHandler(ColumnChangedEventHandler); } } if (myDT != null) { myDT.ExtendedProperties.Clear(); } myDT = null; } myMngr = null; } } isDisposed = true; }