Exemplo n.º 1
0
		bool UpdateDataBases (TransportData Results)
			{
			foreach (String TableName in Results.ResultsOfCommandsToRun.Keys)
				{
				DataSet ResultDataSet = Results.ResultsOfCommandsToRun [TableName];
				if (ResultDataSet.Tables [TableName] == null)
					continue;
				List<String> UniqueIDForThisTable = Results.GetUniqueIdsForTable (TableName);
				int NumberOfEntriesToProcess = ResultDataSet.Tables [TableName].Rows.Count;
				if (WMB.Basics.IsTestRun)
					WMB.Basics.ReportInformationToEventViewer("Aus der Tabelle \"" + TableName + "\" werden "
						+ Convert.ToString(NumberOfEntriesToProcess) + " in die DatenBank \""
						+ DataBase.DefaultConnectionStringName + "\" übertragen");
				foreach (DataRow InputRow in ResultDataSet.Tables[TableName].Rows)
					{
					List<String> WhereClauseEntries = new List<String> ();
					String ConcatenatedIDField = String.Empty;
					String ConcatenetedIDContent = String.Empty;
					foreach (String IDEntry in UniqueIDForThisTable)
						{
						if (String.IsNullOrEmpty (IDEntry))
							continue;
						String [] IDENtries = IDEntry.Split (',');
						if (IDENtries [1] == "int")
							{
							WhereClauseEntries.Add (" (" + IDENtries [0] + " = " + Convert.ToString (InputRow [IDENtries [0]]) + ") ");
							}
						if (IDENtries [1] == "String")
							{
							WhereClauseEntries.Add (" (" + IDENtries [0] + " = '" + Convert.ToString (InputRow [IDENtries [0]]) + "') ");
							if (UniqueIDForThisTable.Count > 1)
								{
								ConcatenatedIDField = ConcatenatedIDField + IDENtries [0];
								ConcatenetedIDContent = ConcatenetedIDContent + Convert.ToString (InputRow [IDENtries [0]]);
								}
							}
						if (IDENtries [1] == "DateTime")
							{
							WhereClauseEntries.Add (" (" + IDENtries [0] + " = '"
								+ WMB.Basics.GetSelectFormattedDateTime (Convert.ToDateTime(InputRow [IDENtries [0]]))
								+ "') ");
							}
						}
					String WhereClause = String.Empty;
					if (WhereClauseEntries.Count > 0)
						WhereClause = " where " + String.Join (" and ", WhereClauseEntries.ToArray ()) + " ";
					else
						{
						DataBase.RunSQLBatch ("Delete from " + TableName);
						}
					String SelectStatement = "Select * from " + TableName + WhereClause;
					DataSet OldDataDataSet = DataBase.GetCommonDataSet (SelectStatement);
					if (OldDataDataSet.Tables.Count != 1)
						throw new Exception (("DataBase Fehler bei \"" + SelectStatement + "\""));
					DataRow RowToUpdate = null;
					if (OldDataDataSet.Tables [TableName].Rows.Count == 0)
						{
						RowToUpdate = OldDataDataSet.Tables [TableName].NewRow ();
						}
					else
						{
						RowToUpdate = OldDataDataSet.Tables [TableName].Rows [0];
						}
					bool UpdateRequired = false;
					foreach (DataColumn Col in ResultDataSet.Tables [TableName].Columns)
						{
						if (String.Compare (RowToUpdate [Col.ColumnName].ToString (), InputRow [Col.ColumnName].ToString ()) == 0)
							continue;
						if (Col.DataType == typeof (Decimal))
							{
							if ((InputRow [Col.ColumnName] != Convert.DBNull)
								&& (RowToUpdate [Col.ColumnName] != Convert.DBNull))
								if (Convert.ToDecimal (RowToUpdate [Col.ColumnName]) == Convert.ToDecimal (InputRow [Col.ColumnName]))
									continue;
							}
						RowToUpdate [Col.ColumnName] = InputRow [Col.ColumnName];
						UpdateRequired = true;
						}
					if (UniqueIDForThisTable.Count > 1)
						{
						if (String.Compare (RowToUpdate [ConcatenatedIDField].ToString (), ConcatenetedIDContent) != 0)
							{
							RowToUpdate [ConcatenatedIDField] = ConcatenetedIDContent;
							UpdateRequired = true;
							}

						}
					if (OldDataDataSet.Tables [TableName].Rows.Count == 0)
						{
						OldDataDataSet.Tables [TableName].Rows.Add (RowToUpdate);
						}
					if (UpdateRequired)
						DataBase.SetCommonDataSet (OldDataDataSet);
					}
				}
			return true;
			}
Exemplo n.º 2
0
		static bool ProcessCreateCommandsFoNextRun (String TransportDirectoryName)
			{
			if (File.Exists(TransportData.DataBaseCommandsToProcessFileName(TransportDirectoryName)))
				{
				if (WMB.Basics.IsTestRun)
					WMB.Basics.ReportInformationToEventViewer("AEAGLeisureManagement.ProcessCreateCommandsFoNextRun",
						"Nothing to do because File \""
						+ TransportData.DataBaseCommandsToProcessFileName(TransportDirectoryName)
						+ "\" exists");
				return true;
				}
			if (WMB.Basics.IsTestRun)
				WMB.Basics.ReportInformationToEventViewer ("AEAGLeisureManagement.ProcessCreateCommandsFoNextRun",
					"A fresh CommandsToProcess File, named \""
					+ TransportData.DataBaseCommandsToProcessFileName(TransportDirectoryName)
					+ "\" will be created");
			TransportData NewCommandsToProcess = new TransportData();
			NewCommandsToProcess.RootDirectory = TransportDirectoryName;
//			Commands.FillBasicData (); //TODO use only in case of complete restart with DataBase recreation
			NewCommandsToProcess.FillStandardBookingData();
			String WrittenFileName = NewCommandsToProcess.WriteMeOutAsCommandsToProcess();
			if (WMB.Basics.IsTestRun)
				WMB.Basics.ReportInformationToEventViewer ("AEAGLeisureManagement.ProcessCreateCommandsFoNextRun",
					"File \"" + WrittenFileName + "\" has been written");
			return true;
			}