public void InitializeMe (String Bereich, WCFStandardsNS.WCFStandards DataBase, CommonDataBase.StatusCallBack StatusCallbackHandler) { SetMessageCallback (StatusCallbackHandler); m_DataBase = DataBase; m_ShowFullPage.InitializeMe (Bereich, m_DataBase, m_StatusCallBackHandler); }
public bool SetData (CommonDataBase.DataBase DataBase, Object Sender, String Bereich, DataSet SchemaDataSet, TableContentDefinition [] TableContentDefinitions, TableLayoutDefinition TableLayoutDefinitions) { m_TableLayoutDefinition = TableLayoutDefinitions; bool ReturnCode = m_CommonUserInterface.SetData (DataBase, Sender, Bereich, SchemaDataSet, TableContentDefinitions, TableLayoutDefinitions); m_CommonUserInterface.GetReadableTextForEntryCall += new GetReadableTextForEntryEvent (m_CommonUserInterface_GetReadableTextForEntryCall); return ReturnCode; }
public void InitializeMe (String Bereich, WCFStandardsNS.WCFStandards DataBase, CommonDataBase.StatusCallBack StatusCallBackHandler) { m_Bereich = Bereich; m_DataBase = DataBase; SetMessageCallback (StatusCallBackHandler); if (m_StructureDataSet != null) m_StructureDataSet.Dispose (); m_StructureDataSet = null; LoadStructure (); }
public static void DropTable (CommonDataBase.DataBase DataBaseInstance, String TableName) { DataBaseInstance.RunSQLBatch (String.Format (m_DropTableTemplate, TableName)); }
public static void DropView (CommonDataBase.DataBase DataBaseInstance, String ViewName) { DataBaseInstance.RunSQLBatch (String.Format (m_DropViewTemplate, ViewName)); }
public void SetMessageCallback (CommonDataBase.StatusCallBack StatusCallBackHandler) { m_StatusCallBackHandler = StatusCallBackHandler; }
public static void RemoveViaID (CommonDataBase.DataBase DataBaseInstance, String TableName, String IDName, String IDToRemove) { if (String.IsNullOrEmpty (TableName)) return; if (String.IsNullOrEmpty (IDName)) return; if (String.IsNullOrEmpty (IDToRemove)) return; String DeleteCommand = "Delete from [" + TableName + "] where " + IDName + " = '" + IDToRemove + "'"; DataBaseInstance.RunSQLBatch (DeleteCommand); }
public static String CreateConnector (CommonDataBase.DataBase DataBaseInstance, String FromID, String ToID, bool InsertIfMissing, String TableName, String FromIDName, String ToIDName) { if (String.IsNullOrEmpty (FromID)) return null; if (String.IsNullOrEmpty (ToID)) return null; DataSet ExistingConnectorDataSet = DataBaseInstance.GetCommonDataSet ("Select * from " + TableName + " where " + FromIDName + " = '" + FromID + "' and " + ToIDName + " = '" + ToID + "'"); if (ExistingConnectorDataSet.Tables [0].Rows.Count > 0) return ExistingConnectorDataSet.Tables [0].Rows [0] ["ID"].ToString (); if (!InsertIfMissing) return null; DataRow ProcessingRow = ExistingConnectorDataSet.Tables [0].NewRow (); ProcessingRow ["ID"] = System.Guid.NewGuid (); ProcessingRow [FromIDName] = FromID; ProcessingRow [ToIDName] = ToID; ExistingConnectorDataSet.Tables [0].Rows.Add (ProcessingRow); DataBaseInstance.SetCommonDataSet (ExistingConnectorDataSet); return ProcessingRow ["ID"].ToString (); }
public static String GetID (CommonDataBase.DataBase DataBaseInstance, String IDsText, String PreferedID, bool InsertIfMissing, String TableName, String IDsTextName, String SecondIDsText, String SecondIDsTextName) { DataSet ExistingEntriesDataSet = DataBaseInstance.GetCommonDataSet ("Select * from " + TableName + " where UPPER(" + IDsTextName + ") = UPPER('" + ConvertEscape (IDsText.Trim ()) + "') and UPPER(" + SecondIDsTextName + ") = UPPER('" + ConvertEscape (SecondIDsText.Trim ()) + "')"); if (ExistingEntriesDataSet.Tables [0].Rows.Count > 0) return ExistingEntriesDataSet.Tables [0].Rows [0] ["ID"].ToString (); if (!InsertIfMissing) return null; DataRow ProcessingRow = ExistingEntriesDataSet.Tables [0].NewRow (); if (!String.IsNullOrEmpty (PreferedID)) ProcessingRow ["ID"] = PreferedID; else ProcessingRow ["ID"] = System.Guid.NewGuid (); ProcessingRow [IDsTextName] = IDsText.Trim ().Replace ('´', '\'').Replace ('\xB4', '\''); ProcessingRow [SecondIDsTextName] = SecondIDsText.Trim ().Replace ('´', '\'').Replace ('\xB4', '\''); ExistingEntriesDataSet.Tables [0].Rows.Add (ProcessingRow); DataBaseInstance.SetCommonDataSet (ExistingEntriesDataSet); return ProcessingRow ["ID"].ToString (); }
public static bool SecureDirectoryDelete (String DirectoryName, CommonDataBase.StatusCallBack StatusCallBackHandler) { if (!Directory.Exists (DirectoryName)) return true; try { DirectoryInfo DInfo = new DirectoryInfo (DirectoryName); DInfo.Attributes = FileAttributes.Normal; Directory.Delete (DirectoryName); } catch (Exception Excp) { if (StatusCallBackHandler != null) StatusCallBackHandler (900, "Fehler beim DirectoryDelete von \"" + DirectoryName + "\"\r\n" + Excp.ToString()); return false; } return true; }
public static bool SecureFileDelete (String FileName, CommonDataBase.StatusCallBack StatusCallBackHandler) { if (!File.Exists (FileName)) return true; try { FileInfo FInfo = new FileInfo (FileName); FInfo.Attributes = FileAttributes.Normal; File.Delete (FileName); } catch (Exception Excp) { if (StatusCallBackHandler != null) StatusCallBackHandler (900, "Fehler beim FileDelete von \"" + FileName + "\"\r\n" + Excp.ToString()); return false; } return true; }
private static bool DeleteRuntimeDataBase (ref CommonDataBase.DataBase DataBaseInstance, String DataBaseName, String DataBaseFileName, CommonDataBase.StatusCallBack StatusCallBackHandler) { String DetachCommand = String.Format (m_DetachDataBaseTemplate, DataBaseName); try { if (StatusCallBackHandler != null) StatusCallBackHandler (200, DataBaseName + " Detach Started"); DataBaseInstance.RunSQLBatch (DetachCommand); if (StatusCallBackHandler != null) StatusCallBackHandler (210, DataBaseName + " Completely detached"); } catch (Exception Excp) { if (StatusCallBackHandler != null) StatusCallBackHandler (998, DetachCommand); if (StatusCallBackHandler != null) StatusCallBackHandler (999, "CommonBasics.DeleteRuntimeDataBase\r\n" + Excp.ToString()); return false; } if ((SecureFileDelete (DataBaseFileName, StatusCallBackHandler) == false) || (SecureFileDelete (DataBaseFileName.Replace (".mdf", ".ldf"), StatusCallBackHandler) == false)) if (StatusCallBackHandler != null) { StatusCallBackHandler (999, "Ein oder beide Datenbanken Files\r\n(\"" + DataBaseFileName + "\",\r\n\"" + DataBaseFileName.Replace (".mdf", ".ldf") + "\")\r\nkonnte(n) nicht gelöscht werden"); return false; } return true; }
public static bool RemoveDataBase (ref CommonDataBase.DataBase DataBaseInstance, String DataBaseName, String DataBaseFileName, String ConnectionStringTemplate, CommonDataBase.StatusCallBack StatusCallBackHandler) { DataBaseInstance = new DataBase (String.Format (ConnectionStringTemplate, "Master")); DataBaseInstance.SetMessageCallback (StatusCallBackHandler); bool Return = DeleteRuntimeDataBase (ref DataBaseInstance, DataBaseName, DataBaseFileName, StatusCallBackHandler); DataBaseInstance.Close (); return Return; }
public static Process StartExternalProgramm (String ProgramName, String Parameter, CommonDataBase.StatusCallBack StatusCallBackHandler, bool UseWorkingDirectory = true) { if (!System.IO.Path.IsPathRooted (ProgramName)) { ProgramName = Path.Combine (Directory.GetCurrentDirectory (), ProgramName); } if (!System.IO.File.Exists (ProgramName)) { if (StatusCallBackHandler != null) StatusCallBackHandler (999, "StartExternalProgramm,\r\n" + "der File " + ProgramName + " existiert nicht"); return null; } String ProcessName = System.IO.Path.GetFileNameWithoutExtension (ProgramName); ProcessStartInfo PSI = new ProcessStartInfo (ProgramName, Parameter); if (UseWorkingDirectory) PSI.WorkingDirectory = System.IO.Path.GetDirectoryName (ProgramName); Process ProcessID = Process.Start (PSI); ProcessID.EnableRaisingEvents = true; return ProcessID; }
public static bool ConnectToRuntimeDataBase (ref CommonDataBase.DataBase DataBaseInstance, String DataBaseName, String DataBaseFileName, String ConnectionStringTemplate, String [] TablesCreationCommands, CommonDataBase.StatusCallBack StatusCallBackHandler) { if (!File.Exists (DataBaseFileName)) { DataBaseInstance = new DataBase (String.Format (ConnectionStringTemplate, "Master")); DataBaseInstance.SetMessageCallback (StatusCallBackHandler); CreateRuntimeDataBase (ref DataBaseInstance, DataBaseName, DataBaseFileName, StatusCallBackHandler); DataBaseInstance.Close (); if (DataBaseFileName.IndexOf (".db", StringComparison.OrdinalIgnoreCase) == -1) DataBaseInstance = new DataBase (String.Format (ConnectionStringTemplate, DataBaseName)); else DataBaseInstance = new DataBase (String.Format (ConnectionStringTemplate, DataBaseFileName)); DataBaseInstance.SetMessageCallback (StatusCallBackHandler); CreateRuntimeTables (ref DataBaseInstance, DataBaseName, TablesCreationCommands, StatusCallBackHandler); DataBaseInstance.Close (); } else { DataBaseInstance = new DataBase (String.Format (ConnectionStringTemplate, "Master")); DataBaseInstance.SetMessageCallback (StatusCallBackHandler); AttachDataBase (DataBaseInstance, DataBaseName, DataBaseFileName); DataBaseInstance.Close (); if (DataBaseFileName.IndexOf (".db", StringComparison.OrdinalIgnoreCase) == -1) DataBaseInstance = new DataBase (String.Format (ConnectionStringTemplate, DataBaseName)); else DataBaseInstance = new DataBase (String.Format (ConnectionStringTemplate, DataBaseFileName)); DataBaseInstance.SetMessageCallback (StatusCallBackHandler); } return true; }
public static Process StartExternalAssoziation (String FileName, String Verb, CommonDataBase.StatusCallBack StatusCallBackHandler) { if (!System.IO.Path.IsPathRooted (FileName)) { FileName = Path.Combine (Directory.GetCurrentDirectory (), FileName); } if (!System.IO.File.Exists (FileName)) { if (StatusCallBackHandler != null) StatusCallBackHandler (999, "StartExternalProgramm,\r\n" + "der File " + FileName + " existiert nicht"); return null; } String ProcessName = System.IO.Path.GetFileNameWithoutExtension (FileName); ProcessStartInfo PSI = new ProcessStartInfo (FileName); PSI.Verb = Verb; PSI.CreateNoWindow = true; Process ProcessID = Process.Start (PSI); ProcessID.EnableRaisingEvents = true; return ProcessID; }
private static bool CreateRuntimeDataBase (ref CommonDataBase.DataBase DataBaseInstance, String DataBaseName, String DataBaseFileName, CommonDataBase.StatusCallBack StatusCallBackHandler) { String PureFileName = Path.GetFileNameWithoutExtension (DataBaseFileName); String DataBaseDirectory = Path.GetDirectoryName (DataBaseFileName); if (!Directory.Exists (DataBaseDirectory)) { Directory.CreateDirectory (DataBaseDirectory); } DetachDataBase (DataBaseInstance, DataBaseName); String CreationCommand; if (String.Compare (Path.GetExtension (DataBaseFileName), ".mdf", true) == 0) { CreationCommand = String.Format (m_CreateDataBaseTemplate, DataBaseName, DataBaseFileName, DataBaseFileName.Replace (".mdf", ".ldf")); try { if (StatusCallBackHandler != null) StatusCallBackHandler (200, PureFileName + " Detach Started"); DataBaseInstance.RunSQLBatch (CreationCommand); if (StatusCallBackHandler != null) StatusCallBackHandler (210, PureFileName + " Successfully ended"); } catch (Exception Excp) { if (StatusCallBackHandler != null) StatusCallBackHandler (999, CreationCommand); if (StatusCallBackHandler != null) StatusCallBackHandler (999, "CommonBasics.CreateRuntimeDataBase\r\n" + Excp.ToString()); return false; } return true; } else { //File.Create (DataBaseFileName); return true; } try { if (StatusCallBackHandler != null) StatusCallBackHandler (200, PureFileName + " Creation Started"); DataBaseInstance.RunSQLBatch (CreationCommand); if (StatusCallBackHandler != null) StatusCallBackHandler (210, PureFileName + " Successfully ended"); } catch (Exception Excp) { if (StatusCallBackHandler != null) StatusCallBackHandler (999, CreationCommand); if (StatusCallBackHandler != null) StatusCallBackHandler (999, "CommonBasics.CreateRuntimeDataBase\r\n" + Excp.ToString()); return false; } return true; }
public static void RemoveUnusedConnectors (CommonDataBase.DataBase DataBaseInstance, String TableName, String LiedID, NameValueCollection CorrectIDs) { DataSet ExistingConnectors = DataBaseInstance.GetCommonDataSet ("Select * from " + TableName + " " + "where LiedID = '" + LiedID + "'"); foreach (String CorrectKey in CorrectIDs.AllKeys) { DataRow [] ConnectorEntries = ExistingConnectors.Tables [0].Select ("ID = '" + CorrectKey + "'"); int Index = 0; while (Index < ConnectorEntries.Length) ConnectorEntries [Index++].Delete (); } ExistingConnectors.Tables [0].AcceptChanges (); if (ExistingConnectors.Tables [0].Rows.Count > 0) { int DelIndex = 0; while (DelIndex < ExistingConnectors.Tables [0].Rows.Count) ExistingConnectors.Tables [0].Rows [DelIndex++].Delete (); DataBaseInstance.SetCommonDataSet (ExistingConnectors); } }
public static bool CreateRuntimeTables (ref CommonDataBase.DataBase DataBaseInstance, String DataBaseName, String [] TableCreationCommands, CommonDataBase.StatusCallBack StatusCallBackHandler) { if (StatusCallBackHandler != null) StatusCallBackHandler (220, "CommonBasics.CreateRuntimeTables Started"); foreach (String TableCreationCommand in TableCreationCommands) { try { DataBaseInstance.RunSQLBatch (String.Format (TableCreationCommand, DataBaseName)); } catch (Exception Excp) { if (StatusCallBackHandler != null) StatusCallBackHandler (999, TableCreationCommand); if (StatusCallBackHandler != null) StatusCallBackHandler (999, "CommonBasics.CreateRuntimeTables\r\n" + Excp.ToString()); return false; } } if (StatusCallBackHandler != null) StatusCallBackHandler (230, "CommonBasics.CreateRuntimeTables Successfully ended"); return true; }
public static int RemoveConnector (CommonDataBase.DataBase DataBaseInstance, String TableName, String IDName, String IDToRemove) { if (String.IsNullOrEmpty (TableName)) return 0; if (String.IsNullOrEmpty (IDName)) return 0; if (String.IsNullOrEmpty (IDToRemove)) return 0; DataSet ExistingConnectorDataSet = DataBaseInstance.GetCommonDataSet ("Select * from " + TableName + " where " + IDName + " = '" + IDToRemove + "'"); int ConnectionCounter = 0; foreach (DataRow RowToDelete in ExistingConnectorDataSet.Tables [TableName].Rows) { String DeleteCommand = "Delete from [" + TableName + "] where " + IDName + " = '" + IDToRemove + "'"; DataBaseInstance.RunSQLBatch (DeleteCommand); ConnectionCounter++; } return ConnectionCounter; }
public static void AttachDataBase (CommonDataBase.DataBase DataBaseInstance, String DataBaseName, String DataBaseFileName) { DetachDataBase (DataBaseInstance, DataBaseName); String AttachCommand = String.Format (m_AttachDataBaseTemplate, DataBaseName, DataBaseFileName, DataBaseFileName.Replace (".mdf", ".ldf")); DataBaseInstance.RunSQLBatch (AttachCommand); }
public static int RemoveUnusedKeyEntries (CommonDataBase.DataBase DataBaseInstance, String TableName, String IDName, String IDToRemove, String [] ConnectionTablesToCheck, String [] IDNamesToCheck) { int ConnectorIndex = 0; int NumberOfAllConnections = 0; int NumberOfRemovedEntries = 0; foreach (String ConnectorTableName in ConnectionTablesToCheck) { DataSet ConnctorDataSet = DataBaseInstance.GetCommonDataSet (String.Format ("Select count (*) from {0} where {1} = '{2}'", ConnectorTableName, IDNamesToCheck [ConnectorIndex], IDToRemove)); int NumberOfConnections = Convert.ToInt32 (ConnctorDataSet.Tables [0].Rows [0] [0]); NumberOfAllConnections += NumberOfConnections; ConnectorIndex++; } if (NumberOfAllConnections == 0) { RemoveViaID (DataBaseInstance, TableName, IDName, IDToRemove); NumberOfRemovedEntries++; } return NumberOfRemovedEntries; }
public static bool DetachDataBase (CommonDataBase.DataBase DataBaseInstance, String DataBaseName) { DataSet DataBases = DataBaseInstance.GetCommonDataSet ("Select Name from sys.databases"); bool DetachIsNecessary = false; foreach (DataRow DataBaseRow in DataBases.Tables [0].Rows) { if (String.Compare (DataBaseName, DataBaseRow ["name"].ToString (), true) == 0) { DetachIsNecessary = true; break; } } if (DetachIsNecessary) { String DetachCommand = String.Format (m_DetachDataBaseTemplate, DataBaseName); DataBaseInstance.RunSQLBatch (DetachCommand); return true; } return false; }
public bool SetData (CommonDataBase.DataBase DataBase, Object Sender, String Bereich, DataSet SchemaDataSet, TableContentDefinition [] TableContentDefinitions, TableLayoutDefinition TableLayoutDefinition) { m_Bereich = Bereich; m_SchemaDataSet = SchemaDataSet; m_TableContentDefinitions = TableContentDefinitions; m_TableLayoutDefinition = TableLayoutDefinition; if (DataBase != null) m_DataBase = DataBase; else m_DataBase = new DataBase (); if (Sender.GetType () == typeof (ListBox)) { ListBox ListBoxToProcess = (ListBox)Sender; UserData = (ControlUserData)ListBoxToProcess.Tag; if (ListBoxToProcess.SelectedIndex == -1) { return false; } m_ActiveID = ((ListBoxItem)ListBoxToProcess.Items [ListBoxToProcess.SelectedIndex]).Tag.ToString (); } if (Sender.GetType () == typeof (Microsoft.Windows.Controls.DataGrid)) { Microsoft.Windows.Controls.DataGrid DataGridToProcess = (Microsoft.Windows.Controls.DataGrid) Sender; UserData = (ControlUserData)DataGridToProcess.Tag; if (DataGridToProcess.SelectedIndex == -1) { return false; } m_ActiveID = ((DataRowView)DataGridToProcess.SelectedItems [0]).Row ["ID"].ToString (); } m_RefreshmentRoutine = UserData.m_RefreshFunctionName; m_PrimaryKeyName = UserData.m_PrimaryKeyName; //SimpleDataRowWindow DataRowWindow = new SimpleDataRowWindow (); m_ProcessingDataSet = m_DataBase.GetCommonDataSet ( "Select * from " + UserData.m_TableName + " where " + m_PrimaryKeyName + " = '" + m_ActiveID + "'"); SetRowToProcess (m_ProcessingDataSet.Tables [0].Rows [0], "Bitte ändern Sie ggf. die Daten dieser " + UserData.m_TableName, UserData.m_UpdateAble); return true; }
public void SetData (String Bereich, CommonDataBase.DataBase ParentsDataBase, object Sender, string TableNameParameter, String ConnectionFieldName, string ID, string [] Additionals, string [] BackAdditionals) { m_Bereich = Bereich; m_Sender = Sender; TableName = TableNameParameter; m_ID = ID; m_Additionals = Additionals; m_BackAdditionals = BackAdditionals; this.Title = ConnectionFieldName + " aus " + TableName + " kann ausgewählt werden"; if (WMB.WPMediaApplicationState.Instance.Properties ["HandlerFor_" + TableName] != null) m_TableHandlerDefinition = (CommonDataBase.TableHandlerDefinition) WMB.WPMediaApplicationState.Instance.Properties ["HandlerFor_" + TableName]; else m_TableHandlerDefinition = new CommonDataBase.TableHandlerDefinition (null); SelectionRootGrid.Children.Clear (); Assembly SelectionAssembly = Assembly.LoadFrom (m_TableHandlerDefinition.m_SelectionControlAssemblyNameForThisTable); Object SelectionInstance = SelectionAssembly.CreateInstance (m_TableHandlerDefinition.m_SelectionControlClassNameForThisTable); Type SelectionType = SelectionInstance.GetType (); SelectionRootGrid.Children.Add ((System.Windows.UIElement) SelectionInstance); m_ICommonTableInterface = SelectionInstance as ICommonTableInterface; if (m_ICommonTableInterface == null) { throw new NotImplementedException (); } m_ICommonTableInterface.OldID = ID; m_ICommonTableInterface.DataBase = ParentsDataBase; m_ICommonTableInterface.SelectionWindowInstance = this; m_ICommonTableInterface.LayoutDefinitionsPropertyToken = "TableLayoutDefinitions_"; this.SizeToContent = SizeToContent.WidthAndHeight; }