public static String LoadFileContentAsString (Materialien MaterialContainer) { WCFStandards DataAccess = new WCFStandards(); String SelectStatement = "select BlobContent = @BlobParam from Materialien where ID = '" + MaterialContainer.ID.ToString() + "'"; using (MemoryStream Helper = new MemoryStream (DataAccess.GetCommonBlob (SelectStatement))) { return WMB.Basics.ConvertMemoryStreamToString (Helper); } }
public static String GetMaterialLink(Materialien Material) { String [] Result = new String[(int)WMB.DataWrapper.MaterialElementIndex.TechnicalTableLength]; Result[(int)DataWrapper.MaterialElementIndex.UsedConnectionString] = "AltErlaaInfoConnectionString"; Result[(int)DataWrapper.MaterialElementIndex.UsedMaterialTableName] = "Materialien"; Result[(int)DataWrapper.MaterialElementIndex.UsedMaterialTableID] = Material.ID.ToString( ); Result[(int)DataWrapper.MaterialElementIndex.UsedTableName] = ""; Result[(int)DataWrapper.MaterialElementIndex.UsedTableID] = ""; Result[(int)DataWrapper.MaterialElementIndex.UsedNameID] = ""; Result[(int)DataWrapper.MaterialElementIndex.UsedType] = Material.Typ; Result [(int) DataWrapper.MaterialElementIndex.UsedSubEntryID] = Material.SubEntryID; return String.Join(",", Result); }
public static bool InsertNewMaterial(Guid InformationenID, ref InformationenAddOn NewInfAddOn, ref Materialien NewMaterial, MemoryStream MemoryStreamContentToStore, String NameOfTheContentToStore, String TypOfTheContentToStore) { String SizeString = String.Empty; if (MemoryStreamContentToStore.Length < (1024 * 5)) { SizeString = String.Format (" {0:D} Bytes ", MemoryStreamContentToStore.Length); } else { SizeString = String.Format(" {0:D} kB ", MemoryStreamContentToStore.Length / 1024); } Guid InformationenAddOnID = Guid.NewGuid (); Guid MaterialienID = Guid.NewGuid (); NewInfAddOn = new InformationenAddOn(); NewInfAddOn.ID = InformationenAddOnID; NewInfAddOn.InformationenID = InformationenID; NewInfAddOn.Tabelle = "Materialien"; NewInfAddOn.TabelleID = MaterialienID; NewInfAddOn.ActuallBezeichner = "InformationenMaterial"; String StringToStore = WMB.Basics.ConvertMemoryStreamToString(MemoryStreamContentToStore); if (StringToStore.Length > 3999) StringToStore = StringToStore.Substring (0, 3995) + " ..."; NewInfAddOn.FreiText = "Typ = \"" + TypOfTheContentToStore + "\" - " + NameOfTheContentToStore + "." + TypOfTheContentToStore + SizeString + "\r\n" + StringToStore; NewInfAddOn.SortOrder = 45000; // NewInfAddOn.DataDependencyID = Guid.Parse("D8C2E698-4C62-4AA4-A2B2-919E6BB415C8"); NewInfAddOn.DataDependencyID = Guid.Parse("5998F56D-0CA6-4FF4-B768-80C308B37394"); NewInfAddOn.LastModifiedBy = "Auto"; InsertOrModifyEntity (null, NewInfAddOn, true); NewMaterial = new Materialien (); NewMaterial.ID = MaterialienID; NewMaterial.NameID = NameOfTheContentToStore; NewMaterial.InformationenID = InformationenID; NewMaterial.InformationenAddOnID = InformationenAddOnID; NewMaterial.Typ = TypOfTheContentToStore; NewMaterial.OriginalMaterialName = NameOfTheContentToStore; InsertOrModifyEntity(null, NewMaterial, true); CheckOrStoreMaterialBlobContent(NewMaterial, NameOfTheContentToStore, MemoryStreamContentToStore, TypOfTheContentToStore); return true; }
public static Byte [] LoadFileContent (Materialien MaterialContainer) { WCFStandards DataAccess = new WCFStandards (); String SelectStatement = "select BlobContent = @BlobParam from Materialien where ID = '" + MaterialContainer.ID.ToString() + "'"; return DataAccess.GetCommonBlob (SelectStatement); }
public static String GetMaterialContentViaName (Guid InformationenID, String NameOfTheContentToStore, out Materialien Material) { AltErlaaInfoEntities MaterialReader = new AltErlaaInfoEntities(); Material = (from Mat in MaterialReader.Materialien where Mat.InformationenID == InformationenID && Mat.NameID == NameOfTheContentToStore select Mat).FirstOrDefault(); if ((Material == null) || (Material.ID == Guid.Empty)) return String.Empty; return LoadFileContentAsString (Material); }
public static bool InsertNewMaterial(Guid InformationenID, ref InformationenAddOn InfoAddOnID, ref Materialien Material, String ContentToStore, String NameOfTheContentToStore, String TypOfTheContentToStore) { return InsertNewMaterial(InformationenID, ref InfoAddOnID, ref Material, WMB.Basics.ConvertStringToMemoryStream (ContentToStore), NameOfTheContentToStore, TypOfTheContentToStore); }
public static String ModifyMaterialContentViaName(Materialien Material, String NewStringContentToUse, String NameOfTheNewContentToStore = "", String TypOfTheContentToStore = "") { Byte [] NewContent = ModifyMaterialContentViaName (Material, WMB.Basics.ConvertStringToMemoryStream (NewStringContentToUse), NameOfTheNewContentToStore, TypOfTheContentToStore); if (NewContent == null) return String.Empty; return WMB.Basics.ConvertByteArrayToString (NewContent); }
public static Byte[] ModifyMaterialContentViaName(Materialien Material, MemoryStream NewMemoryStreamContentToUse, String NameOfTheNewContentToStore = "", String TypOfTheContentToStore = "") { if ((Material == null) || (Material.ID == Guid.Empty)) return null; if (String.IsNullOrEmpty(NameOfTheNewContentToStore)) NameOfTheNewContentToStore = Material.NameID; if (String.IsNullOrEmpty(TypOfTheContentToStore)) TypOfTheContentToStore = Material.Typ; CheckOrStoreMaterialBlobContent(Material, NameOfTheNewContentToStore, NewMemoryStreamContentToUse, TypOfTheContentToStore); String ModifyAfterBlobChanged = "Update Materialien set BlobLength = " + Convert.ToString (Material.BlobLength) + ", NameID = '" + NameOfTheNewContentToStore + "', Typ = '" + TypOfTheContentToStore + "', ModifyTimeStamp = " + WMB.Basics.GetSQLFormattedDateTime (DateTime.Now) + " where ID = '" + Material.ID.ToString () + "'"; WCFStandards WCFAccess = new WCFStandards (); WCFAccess.DefaultConnectionStringName = "AltErlaaInfoConnectionString"; WCFAccess.RunSQLBatch (ModifyAfterBlobChanged); return LoadFileContent(Material); }
public static bool CheckOrStoreMaterialBlobContent (Materialien MaterialContainer, String FileName, bool FromClipBoard = false) { if ((FromClipBoard) || (FileName.ToUpper().Contains ("CLIPBOARD"))) return CheckOrStoreMaterialBlobContentFromClipBoard (MaterialContainer, FileName); String Extension = System.IO.Path.GetExtension (FileName).Replace (".", "").ToUpper (); FileInfo FInfo = new FileInfo (FileName); if ((FileName == MaterialContainer.OriginalMaterialName) && (FInfo.Length == MaterialContainer.BlobLength) && (MaterialContainer.ModifyTimeStamp > FInfo.LastWriteTime)) { return false; } FileStream FileContent = new FileStream (FileName, FileMode.Open, FileAccess.Read, FileShare.Read); MemoryStream MeoryStreamContent = new MemoryStream (); WMB.Basics.CopyStream (FileContent, MeoryStreamContent); bool ReturnValue = CheckOrStoreMaterialBlobContent (MaterialContainer, FileName, MeoryStreamContent, Extension); FileContent.Close (); return ReturnValue; }
public static bool CheckOrStoreMaterialBlobContent (Materialien MaterialContainer, String OriginalFileName, MemoryStream MeoryStreamContent, String Typ) { MeoryStreamContent.Seek(0, SeekOrigin.Begin); WCFStandardsNS.WCFStandards WCFAccess = new WCFStandards(); WCFAccess.DefaultConnectionStringName = "AltErlaaInfoConnectionString"; String UpdateCommand = "Update Materialien set BlobLength = " + Convert.ToString(MeoryStreamContent.Length) + ", BlobContent = @BlobParam, " + "OriginalMaterialName = '" + OriginalFileName + "', " + "ModifyTimeStamp = " + WMB.Basics.GetSQLFormattedDateTime(DateTime.Now) + ", Typ = '" + Typ + "' where ID = '" + MaterialContainer.ID.ToString() + "'"; WCFAccess.SetCommonBlob(UpdateCommand, MeoryStreamContent.ToArray()); MaterialContainer.Typ = Typ; MaterialContainer.OriginalMaterialName = OriginalFileName; MaterialContainer.BlobLength = (int)MeoryStreamContent.Length; MeoryStreamContent.Close(); return true; }
public static bool CheckOrStoreMaterialBlobContent(Materialien MaterialContainer, String StringName, String Content) { String Extension = System.IO.Path.GetExtension(StringName).Replace(".", "").ToUpper(); bool ReturnValue = CheckOrStoreMaterialBlobContent(MaterialContainer, StringName, WMB.Basics.ConvertStringToMemoryStream(Content), Extension); return ReturnValue; }
public static bool CheckOrStoreMaterialBlobContentFromClipBoard (Materialien MaterialContainer, String FileName) { if (FileName.IndexOf ("Clipboard", StringComparison.CurrentCultureIgnoreCase) == -1) return false; String Extension = System.IO.Path.GetExtension (FileName).Replace (".", "").ToUpper (); MemoryStream MemoryFileContent = null; Object CBData = Clipboard.GetDataObject (); if (CBData == null) { return false; } String ContentFormat = String.Empty; String ClipboardContent = null; BitmapSource ClipboardContentImage = null; IDataObject ObjectInterface = CBData as IDataObject; String [] Formats = ObjectInterface.GetFormats (true); foreach (String Format in Formats) { // Object InnerObject = ObjectInterface.GetData (Format); } if (Clipboard.ContainsText (TextDataFormat.Html)) { ClipboardContent = Clipboard.GetText (TextDataFormat.Html); ContentFormat = Enum.GetName (typeof (TextDataFormat), TextDataFormat.Html); } else if (Clipboard.ContainsText (TextDataFormat.Rtf)) { ClipboardContent = Clipboard.GetText (TextDataFormat.Rtf); ContentFormat = Enum.GetName (typeof (TextDataFormat), TextDataFormat.Rtf); } else if (Clipboard.ContainsText (TextDataFormat.Text)) { ClipboardContent = Clipboard.GetText (TextDataFormat.Text); ContentFormat = Enum.GetName (typeof (TextDataFormat), TextDataFormat.Text); } else if (Clipboard.ContainsText (TextDataFormat.UnicodeText)) { ClipboardContent = Clipboard.GetText (TextDataFormat.UnicodeText); ContentFormat = Enum.GetName (typeof (TextDataFormat), TextDataFormat.UnicodeText); } else if (Clipboard.ContainsImage ()) { ClipboardContentImage = Clipboard.GetImage (); ContentFormat = "BitmapSource"; } else { ClipboardContent = String.Empty; return false; } if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.Text)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes (ClipboardContent)); } if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.Rtf)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes (ClipboardContent)); } if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.Html)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes (ClipboardContent)); } if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.UnicodeText)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes (ClipboardContent)); } if (ContentFormat == "BitmapSource") { MemoryFileContent = WMB.Basics.ConvertBitmapSourceToJPegStream (ClipboardContentImage); } return CheckOrStoreMaterialBlobContent (MaterialContainer, FileName, MemoryFileContent, Extension); }
bool ProcessSelectedFile (Materialien WorkingMaterialien, String FileName) { if (!File.Exists (FileName)) { MessageBox.Show ("Der File\r\n\"" + FileName + "\"\r\nist auf dieser Maschine nicht verfügbar,\r\n" + "daher können Sie ihn auch nicht ändern"); return false; } if (WMB.Basics.IsThisFileAccessable (FileName) == false) { MessageBox.Show ("Der File\r\n\"" + FileName + "\"\r\nist dzt. nicht zugreifbar,\r\n" + "wahrscheinlich ist er in einem anderen\r\n" + "Programm noch offen. Bitte beheben Sie\r\n" + "das und wählen danach noch einmal aus"); return false; } FileInfo FileInfo = new FileInfo (FileName); if (FileInfo.Length > 3000000) { MessageBox.Show ("Der selektierte File\r\n\"" + FileName + "\"\r\nist " + Convert.ToString (FileInfo.Length / 1024) + " kB lang. Dzt. sind nur Materialien erlaubt,\r\n" + "die kleiner als 3.072 kB (3 MB) sind"); return false; } InsertOrModifyEntity (WorkingMaterialien); CheckOrStoreFileContent (WorkingMaterialien, FileName); WorkingMaterialien.OriginalMaterialName = FileName; return true; }
private void CheckOrStoreFileContent (Materialien MaterialContainer, String FileName) { String Extension = System.IO.Path.GetExtension (FileName).Replace (".", "").ToUpper (); MemoryStream MemoryFileContent = null; if (FileName.IndexOf ("ClipBoard.") == -1) { FileInfo FInfo = new FileInfo (FileName); if ((FileName == MaterialContainer.OriginalMaterialName) && (FInfo.Length == MaterialContainer.BlobLength) && (MaterialContainer.ModifyTimeStamp > FInfo.LastWriteTime)) { return; } FileStream FileContent = new FileStream (FileName, FileMode.Open, FileAccess.Read, FileShare.Read); MemoryFileContent = new MemoryStream (); WMB.Basics.CopyStream (FileContent, MemoryFileContent); FileContent.Close (); } else { if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.Text)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes(ClipboardContent)); } if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.Rtf)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes (ClipboardContent)); } if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.Html)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes (ClipboardContent)); } if (ContentFormat == Enum.GetName (typeof (TextDataFormat), TextDataFormat.UnicodeText)) { MemoryFileContent = new MemoryStream (System.Text.Encoding.UTF8.GetBytes (ClipboardContent)); } if (ContentFormat == "BitmapSource") { MemoryFileContent = WMB.Basics.ConvertBitmapSourceToJPegStream (ClipboardContentImage); } } MemoryFileContent.Seek (0, SeekOrigin.Begin); WCFStandardsNS.WCFStandards WCFAccess = new WCFStandards (); WCFAccess.DefaultConnectionStringName = "AltErlaaInfoConnectionString"; String UpdateCommand = "Update Materialien set BlobLength = " + Convert.ToString (MemoryFileContent.Length) + ", BlobContent = @BlobParam, " + "OriginalMaterialName = '" + FileName + "', " + "ModifyTimeStamp = " + WMB.Basics.GetSQLFormattedDateTime (DateTime.Now) + ", Typ = '" + Extension + "' where ID = '" + MaterialContainer.ID.ToString () + "'"; WCFAccess.SetCommonBlob (UpdateCommand, MemoryFileContent.ToArray ()); MaterialContainer.Typ = Extension; MaterialContainer.OriginalMaterialName = FileName; MaterialContainer.BlobLength = (int) MemoryFileContent.Length; MemoryFileContent.Close (); }
private String FormatFreitext (Materialien MaterialienDaten, TemplateHandling.FreiTextFormat Format) { if (MaterialienDaten == null) return String.Empty; StringBuilder Elemente = new StringBuilder (); if (!String.IsNullOrEmpty (MaterialienDaten.OriginalMaterialName)) Elemente.Append ("Typ = \"" + MaterialienDaten.Typ + "\" - " + System.IO.Path.GetFileName (MaterialienDaten.OriginalMaterialName)); if ((MaterialienDaten.BlobLength != null) && (MaterialienDaten.ModifyTimeStamp != null)) { Elemente.AppendLine (); Elemente.Append (Convert.ToString (MaterialienDaten.BlobLength/1024) + " kB, zuletzt geschrieben " + ((DateTime) MaterialienDaten.ModifyTimeStamp).ToString (WMB.Basics.ISO_DATE_TIME_FORMAT)); } return Elemente.ToString ().Replace (" ", " "); }