public static bool CreateOrModifyAsStandBildLayout (String TableName, System.Guid ID, String StandBildLayoutNameID) { WCFStandardsNS.WCFStandards DataAccess = new WCFStandards (); DataAccess.DefaultConnectionStringName = "WPMediaAddOnDataConnectionString"; CVM.GraphicsHandling GraphicsHandler = new GraphicsHandling(Basics.GetLocalWPMediaRoot ()); Object Pkg = GraphicsHandler.GetInstatiatedPackage (TableName, ID.ToString ()); List<BitmapSource> CreatedPictures = GraphicsHandler.GetFinalPictures (); int SubEntryIndex = 0; DataSet ExistingMaterials = DataAccess.GetCommonDataSet ("Select " + MATERIALIEN_ITEM_LIST + " from Materialien " + "where Tabelle = '" + TableName + "' and TabelleID = '" + ID.ToString () + "' order by SubEntryID"); if (ExistingMaterials.Tables ["Materialien"].Rows.Count > 0) { int PictureIndex = 0; List<DataRow> RowsToDelete = new List<DataRow> (); foreach (DataRow Existing in ExistingMaterials.Tables ["Materialien"].Rows) { PictureIndex = Convert.ToInt32 (Existing ["SubEntryID"].ToString ().Replace (LAYOUT_PICTURE_PREFIX, "")); if ((PictureIndex - 1) < CreatedPictures.Count) { Byte [] JpegContent = GetJpgByteArrayFromBitmapSource (CreatedPictures [PictureIndex - 1]); String UpdateStatement = String.Format ("Update Materialien " + "set NameID = '{0}', Tabelle = '{1}', TabelleID = '{2}', Typ = '{3}', SubEntryID = '{4}', " + "BlobLength = {5}, BlobContent = @BlobParam, " + "ModifyTimeStamp = '{6}', ProcessingStatus = '{7}', CreatedBy = '{8}' where ID = '{9}'", StandBildLayoutNameID, TableName, ID.ToString (), "", String.Format (LAYOUT_PICTURE_PREFIX_FORMAT, PictureIndex), JpegContent.Length, DateTime.Now.ToString (Basics.ISO_DATE_TIME_FORMAT), "", WMB.WPMediaApplicationState.Instance.Properties ["UserName"].ToString (), Existing ["ID"].ToString ()); DataAccess.SetCommonBlob (UpdateStatement, JpegContent); } else { RowsToDelete.Add (Existing); } } foreach (DataRow ToDelete in RowsToDelete) { String DeleteStatement = "Delete Materialien where ID = '" + ToDelete ["ID"].ToString () + "'"; DataAccess.RunSQLBatch (DeleteStatement); } while ((PictureIndex) < CreatedPictures.Count) { System.Guid PictureID = System.Guid.NewGuid (); Byte [] JpegContent = GetJpgByteArrayFromBitmapSource (CreatedPictures [PictureIndex]); String InsertStatement = String.Format ("Insert into Materialien " + "(ID, NameID, Tabelle, TabelleID, Typ, SubEntryID, BlobLength, BlobContent, ModifyTimeStamp, ProcessingStatus, CreatedBy) " + "Values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', {6}, @BlobParam, '{7}', '{8}', '{9}')", PictureID.ToString (), StandBildLayoutNameID, TableName, ID.ToString (), "", String.Format (LAYOUT_PICTURE_PREFIX_FORMAT, PictureIndex), JpegContent.Length, DateTime.Now.ToString (Basics.ISO_DATE_TIME_FORMAT), "", WMB.WPMediaApplicationState.Instance.Properties ["UserName"].ToString ()); DataAccess.SetCommonBlob (InsertStatement, JpegContent); PictureIndex++; } } else { foreach (BitmapSource Picture in CreatedPictures) { System.Guid PictureID = System.Guid.NewGuid (); Byte [] JpegContent = GetJpgByteArrayFromBitmapSource (Picture); String InsertStatement = String.Format ("Insert into Materialien " + "(ID, NameID, Tabelle, TabelleID, Typ, SubEntryID, BlobLength, BlobContent, ModifyTimeStamp, ProcessingStatus, CreatedBy) Values (" + "'{0}', '{1}', '{2}', '{3}', '{4}', '{5}', {6}, @BlobParam, '{7}', '{8}', '{9}')", PictureID.ToString (), StandBildLayoutNameID, TableName, ID.ToString (), "", String.Format (LAYOUT_PICTURE_PREFIX_FORMAT, SubEntryIndex + 1), JpegContent.Length, DateTime.Now.ToString (Basics.ISO_DATE_TIME_FORMAT), "", WMB.WPMediaApplicationState.Instance.Properties ["UserName"].ToString ()); DataAccess.SetCommonBlob (InsertStatement, JpegContent); SubEntryIndex++; } } return true; }
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; }
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 (); }