Category: Soft/Programming

  • C#: получить имя юнита и номер строки с ошибкой

    Если в сборку включена отладочная информация, то:

    string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); 
    int currentLine = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
    
  • ShareIt currency conversion

    I do not understand what currency exchange used in ShareIt for online purchases.

    The license price for our Viewer for MS Outlook Messages is 20 EUR

    Yesterday customer from USA ordered the license and payed $27.44 (he sent to me the pdf with invoice). But as I see from online reports in ShareIt Control Panel the same transaction counted as $24.21

    1. $24.21 is more “correct” due current exchange rates
    2. but why they charged the customer for additionally $3.23 ????

    This is not first time when I see the incorrect transactions in invoices. But still now I do not understand the algorithm for currency exchange in ShareIt:-(

  • dbViewer: export to PDF

    In all our db-viewers (Paradox, dBase, DBISAM, Clarion) I added the possibility to generate the PDF file with table of records

  • SMExport: Embedded images in html

    Today I added the new feature for TSMExportToHTML component – the possibility to generate the html file with embedded images. Unfortunately the old IE (5/6) do not support this feature but FireFox, Opera, Safari will open the file without any problem

    A few links:
    http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html
    http://rifers.org/blogs/gbevin/2005/4/11/embedding_images_inside_html
    Note: large images will not displayed due some limits in browser for encoded string

  • C#: convert document to PDF

    Today I wrote small code to convert the document (.doc, .rtf etc) ionto PDF format using MS Word 12/2007 automation:

    using Word = Microsoft.Office.Interop.Word;
    
    private void SaveRTFToPDF(string RTFFileName, string PDFFileName)
    		{
    			object oMissing = System.Reflection.Missing.Value;
    			Object oTrue = true;
    			Object oFalse = false;
    			object ReadOnly = false;
    			object IsVisible = true;
    
    			object RTFFile = RTFFileName;
    			object PDFFile = PDFFileName;
    
    			Word._Application oWord = new Word.Application();
    
    			Word._Document oDoc = oWord.Documents.Open(ref RTFFile,
    				ref oMissing, ref ReadOnly,
    			ref oMissing, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref IsVisible, ref oMissing,
    				ref oMissing, ref oMissing,
    				ref oMissing);
    
    
    			object FileFormat = Word.WdSaveFormat.wdFormatPDF;
    			object LockComments = false;
    			object AddToRecentFiles = true;
    			object ReadOnlyRecommended = false;
    			object EmbedTrueTypeFonts = false;
    			object SaveNativePictureFormat = true;
    			object SaveFormsData = true;
    			object SaveAsAOCELetter = false;
    			object InsertLineBreaks = false;
    			object AllowSubstitutions = false;
    			object LineEnding = Word.WdLineEndingType.wdCRLF;
    			object AddBiDiMarks = false;
    
    			oDoc.SaveAs(ref PDFFile, ref FileFormat, ref LockComments,
    				ref oMissing, ref AddToRecentFiles, ref oMissing,
    				ref ReadOnlyRecommended, ref EmbedTrueTypeFonts,
    				ref SaveNativePictureFormat, ref SaveFormsData,
    				ref SaveAsAOCELetter, ref oMissing, ref InsertLineBreaks,
    				ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
    
    			oDoc.Close(ref oFalse, ref oMissing, ref oMissing);
    			oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
    		}
    

    Sample to use:

    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-052561_1.RTF", @"d:\C#\rtf2pdf\rtf\10-052561_1.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-052561_2.RTF", @"d:\C#\rtf2pdf\rtf\10-052561_2.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-072410.RTF", @"d:\C#\rtf2pdf\rtf\10-072410.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-080976.RTF", @"d:\C#\rtf2pdf\rtf\10-080976.pdf");
    			SaveRTFToPDF(@"d:\C#\rtf2pdf\rtf\10-087077.RTF", @"d:\C#\rtf2pdf\rtf\10-087077.pdf");
    

    I tried to convert the rtf into PDF using Crystal Reports. Just to generate the report form on fly from code and print there the RichTextBox.
    But unfortunatelly only simple rtf-files exported as PDF in such way because Crystal Reports supports the limited syntax of rtf-format.
    For example, header/footer of rtf-files is not converted correctly and images are not saved at all.

  • affiliates from ShareIt

    In last few days I got a lot of requests to approve the new affiliates via ShareIt control panel. I added only the BetaNews, DownloadPipe and Lockergnome. All others are not added and not declined.

    Do not know why they want to add my products because the affiliates do not work for me. Seems like ShareIt sent the mails to own large affiliates with list of products and I’m there.

  • formating number

    function GetFormattedNumber(Value: Double): string; 
    
      function GetLastPos(const s: string): Integer; 
      begin 
        Result := Pos(DecimalSeparator, s)-1; 
        if (Result < 1) then 
          Result := Length(s) 
      end; 
    
    var 
      i: Integer; 
    begin 
      Result := FloatToStr(Value); 
      i := 3; 
      while (i < GetLastPos(Result)) do 
      begin 
        Insert(' ', Result, GetLastPos(Result)-i+1); 
        Inc(i, 4) 
      end; 
    end;

    Sample to use:

      lblTotal.Caption := GetFormattedNumber(123456.789);
    

    Why I wrote this function? In Delphi I could use the FormatFloat(‘,###’, dbl) but FormatFloat uses the thousand separator which is defined in MS Windows (#160 by default). I need the space char always

  • Viewer for Crystal Reports (*.rpt)

    Today I wrote for Ethan the small tool – viewer for .rpt files.
    User need select the directory with saved report forms, specify the logon info for MS SQL and view/save as pdf the any report:

    Main form for rptview

    There I used the C# because viewer requires the Crystal Reports runtime library and I have the merge modules (for setup/install) only in MS Visual Studio 2003. Didn’t find in CodeGear/Embacadero disks.
    The setup (.msi) created in MS Visual Studio 2003 too

  • C#: enable XP theming for application

    1. use the manifest (compile as resource or as external file)
    2. call the EnableVisualStyles method for Application in Main():

     	static void Main() 
     	{ 
     		Application.EnableVisualStyles(); 
     		Application.Run(new frmMain()); 
     	}
    
  • abadev server

    Paid now for the next year of server hosting in Canada datacenter.