public void ListenTable(string conStr, SyncMonitor monitor) { using (SqlConnection connection = new SqlConnection(conStr)) { //依赖是基于某一张表的,而且查询语句只能是简单查询语句,不能带top或*,同时必须指定所有者,即类似[dbo].[] using (SqlCommand command = new SqlCommand(monitor.listenSql, connection)) { command.CommandType = CommandType.Text; connection.Open(); SqlDependency dependency = new SqlDependency(command); dependency.OnChange += monitor.callBack; SqlDataReader sdr = command.ExecuteReader(); } } }
private void ListenSales() { #region sales SalesThread = new Thread(new ThreadStart(SalesSyncStart)); #region Organizations List<SyncMonitor> Monitors = new List<SyncMonitor>(); SyncMonitor monitorOrganizations = new SyncMonitor(); monitorOrganizations.tableName = "Organizations"; monitorOrganizations.listenSql = "select cmoName from [dbo].[Organizations]"; monitorOrganizations.callBack = new OnChangeEventHandler(dependency_Sales_OnChange); Monitors.Add(monitorOrganizations); #endregion #region SalesOrders SyncMonitor monitorQuotes = new SyncMonitor(); monitorQuotes.tableName = "SalesOrders"; monitorQuotes.listenSql = "select ompSalesOrderID,ompSalesOrderID,ompCustomerPO,ompRequestedShipDate from [dbo].[SalesOrders]"; monitorQuotes.callBack = new OnChangeEventHandler(dependency_Sales_OnChange); Monitors.Add(monitorQuotes); #endregion #region SalesOrderLines SyncMonitor monitorQuoteQuantities = new SyncMonitor(); monitorQuoteQuantities.tableName = "SalesOrderLines"; monitorQuoteQuantities.listenSql = "select omlSalesOrderLineID,omlPartID,omlPartRevisionID,omlPartShortDescription,omlOrderQuantity,omlCreatedDate,omlCreatedBy,omlExtendedPriceBase,omlExtendedDiscountBase,omlUnitPriceBase,uomlClosed from [dbo].[SalesOrderLines]"; monitorQuoteQuantities.callBack = new OnChangeEventHandler(dependency_Sales_OnChange); Monitors.Add(monitorQuoteQuantities); #endregion SyncObject sync = new SyncObject(Monitors); sync.StartListen(this._connStr); #endregion if (this.pSales.Tag != null && (bool)this.pSales.Tag) SalesThread.Start(); }
private void ListenQuotation() { #region Listen QuotationThread = new Thread(new ThreadStart(QuotationSyncStart)); #region Organizations List<SyncMonitor> Monitors = new List<SyncMonitor>(); SyncMonitor monitorOrganizations = new SyncMonitor(); monitorOrganizations.tableName = "Organizations"; monitorOrganizations.listenSql = "select cmoName from [dbo].[Organizations]"; monitorOrganizations.callBack = new OnChangeEventHandler(dependency_Quotation_OnChange); Monitors.Add(monitorOrganizations); #endregion #region Quotes SyncMonitor monitorQuotes = new SyncMonitor(); monitorQuotes.tableName = "Quotes"; monitorQuotes.listenSql = "select uqmpEnquiryReceivedDate, uqmpCustomerReference, uqmpCustomerquoteduedate, qmpQuoteDate, qmpQuoterEmployeeID, qmpCustomerOrganizationID, qmpQuoteID, qmpQuoteContactID, uqmpQuoteStatus, qmpCurrencyRateID from [dbo].[Quotes]"; monitorQuotes.callBack = new OnChangeEventHandler(dependency_Quotation_OnChange); Monitors.Add(monitorQuotes); #endregion #region QuoteQuantities SyncMonitor monitorQuoteQuantities = new SyncMonitor(); monitorQuoteQuantities.tableName = "QuoteQuantities"; monitorQuoteQuantities.listenSql = "select qmqQuoteQuantity, uqmqQuoteLineTotalBase,qmqRevisedUnitPriceBase from [dbo].[QuoteQuantities]"; monitorQuoteQuantities.callBack = new OnChangeEventHandler(dependency_Quotation_OnChange); Monitors.Add(monitorQuoteQuantities); #endregion #region QuoteLines SyncMonitor monitorQuoteLines = new SyncMonitor(); monitorQuoteLines.tableName = "QuoteLines"; monitorQuoteLines.listenSql = "select qmlPartID,qmlQuoteLineID,uqmlCostingNotesText,qmlPartRevisionID,qmlPartShortDescription,uqmldrawingnumber,qmlUnitOfMeasure from [dbo].[QuoteLines]"; monitorQuoteLines.callBack = new OnChangeEventHandler(dependency_Quotation_OnChange); Monitors.Add(monitorQuoteLines); #endregion SyncObject sync = new SyncObject(Monitors); sync.StartListen(this._connStr); #endregion if (this.pQuotation.Tag != null && (bool)this.pQuotation.Tag) QuotationThread.Start(); }
private void ListenPurchase() { #region Purchase PurchaseThread = new Thread(new ThreadStart(PurchaseSync)); #region Organizations List<SyncMonitor> Monitors = new List<SyncMonitor>(); SyncMonitor monitorOrganizations = new SyncMonitor(); monitorOrganizations.tableName = "Organizations"; monitorOrganizations.listenSql = "select cmoName from [dbo].[Organizations]"; monitorOrganizations.callBack = new OnChangeEventHandler(dependency_Purchase_OnChange); Monitors.Add(monitorOrganizations); #endregion #region PurchaseOrders SyncMonitor monitorQuotes = new SyncMonitor(); monitorQuotes.tableName = "PurchaseOrders"; monitorQuotes.listenSql = "select pmpPurchaseOrderID, pmpBuyerEmployeeID, pmpCreatedDate, pmpStatus from [dbo].[PurchaseOrders]"; monitorQuotes.callBack = new OnChangeEventHandler(dependency_Purchase_OnChange); Monitors.Add(monitorQuotes); #endregion #region SalesOrderLines SyncMonitor monitorQuoteQuantities = new SyncMonitor(); monitorQuoteQuantities.tableName = "PurchaseOrderLines"; monitorQuoteQuantities.listenSql = "select pmlPurchaseOrderLineID, pmlPartID, pmlPartShortDescription, pmlPurchaseUnitOfMeasure,pmlPartID,pmlPurchaseQuantity,pmlPurchaseUnitCostBase, pmlTotalExtendedCostBase,pmlDueDate,pmlJobID,pmlPurchaseQuantityReceived,pmlItemType from [dbo].[PurchaseOrderLines]"; monitorQuoteQuantities.callBack = new OnChangeEventHandler(dependency_Purchase_OnChange); Monitors.Add(monitorQuoteQuantities); #endregion SyncObject sync = new SyncObject(Monitors); sync.StartListen(this._connStr); #endregion if (this.pPurchase.Tag != null && (bool)this.pPurchase.Tag) PurchaseThread.Start(); }
private void ListenOperations() { #region Purchase OperationsThread = new Thread(new ThreadStart(OperationsSync)); #region Organizations List<SyncMonitor> Monitors = new List<SyncMonitor>(); SyncMonitor monitorOrganizations = new SyncMonitor(); monitorOrganizations.tableName = "Jobs"; monitorOrganizations.listenSql = "select jmpJobID from [dbo].Jobs"; monitorOrganizations.callBack = new OnChangeEventHandler(dependency_Operations_OnChange); Monitors.Add(monitorOrganizations); #endregion #region PurchaseOrders SyncMonitor monitorQuotes = new SyncMonitor(); monitorQuotes.tableName = "JobOperations"; monitorQuotes.listenSql = "select jmoJobOperationID,jmoJobAssemblyID,jmoOperationType,jmoSetupHours,jmoEstimatedProductionHours,jmoActualProductionHours,jmoWorkCenterID,jmoProductionComplete from [dbo].JobOperations"; monitorQuotes.callBack = new OnChangeEventHandler(dependency_Operations_OnChange); Monitors.Add(monitorQuotes); #endregion SyncObject sync = new SyncObject(Monitors); sync.StartListen(this._connStr); #endregion if (this.pOperations.Tag != null && (bool)this.pOperations.Tag) OperationsThread.Start(); }
private void ListenInternalReject() { #region InternalReject InternalRejectThread = new Thread(new ThreadStart(InternalRejectSync)); #region Organizations List<SyncMonitor> Monitors = new List<SyncMonitor>(); SyncMonitor monitorOrganizations = new SyncMonitor(); monitorOrganizations.tableName = "NonConformances"; monitorOrganizations.listenSql = "select qarNonConformanceID, qarJobID, qarPartID, qarPartShortDescription,qarQuantity, qarJobOperationID, qarCreatedBy, qarNonConformanceText, uqarPreventativeActionText, qarCorrectiveActionText from [dbo].NonConformances"; monitorOrganizations.callBack = new OnChangeEventHandler(dependency_InternalReject_OnChange); Monitors.Add(monitorOrganizations); #endregion #region PurchaseOrders SyncMonitor monitorQuotes = new SyncMonitor(); monitorQuotes.tableName = "JobOperations"; monitorQuotes.listenSql = "select jmoOperationType from [dbo].JobOperations"; monitorQuotes.callBack = new OnChangeEventHandler(dependency_InternalReject_OnChange); Monitors.Add(monitorQuotes); #endregion SyncObject sync = new SyncObject(Monitors); sync.StartListen(this._connStr); #endregion if (this.pInternalReject.Tag != null && (bool)this.pInternalReject.Tag) InternalRejectThread.Start(); }
private void ListenDespatches() { #region Listen DespatchesThread = new Thread(new ThreadStart(DespatchesSync)); #region Organizations List<SyncMonitor> Monitors = new List<SyncMonitor>(); SyncMonitor monitorOrganizations = new SyncMonitor(); monitorOrganizations.tableName = "Organizations"; monitorOrganizations.listenSql = "select cmoName from [dbo].[Organizations]"; monitorOrganizations.callBack = new OnChangeEventHandler(dependency_Despatches_OnChange); Monitors.Add(monitorOrganizations); #endregion #region Quotes SyncMonitor monitorQuotes = new SyncMonitor(); monitorQuotes.tableName = "Shipments"; monitorQuotes.listenSql = "select smpShipDate, smpShipmentID, smpCustomerOrganizationID from [dbo].Shipments"; monitorQuotes.callBack = new OnChangeEventHandler(dependency_Despatches_OnChange); Monitors.Add(monitorQuotes); #endregion #region QuoteQuantities SyncMonitor monitorQuoteQuantities = new SyncMonitor(); monitorQuoteQuantities.tableName = "ShipmentLines"; monitorQuoteQuantities.listenSql = "select smlSalesOrderID, smlJobID, smlPartID, smlShipmentLineID, smlQuantityShipped, smlDescription, smlSalesOrderLineID, smlPartGroupID from [dbo].ShipmentLines"; monitorQuoteQuantities.callBack = new OnChangeEventHandler(dependency_Despatches_OnChange); Monitors.Add(monitorQuoteQuantities); #endregion SyncObject sync = new SyncObject(Monitors); sync.StartListen(this._connStr); #endregion if (this.pDespatches.Tag != null && (bool)this.pDespatches.Tag) DespatchesThread.Start(); }