Wednesday 30 March 2011

Final Year Project

Just wanna share with u guys about my final year project for my bachelor's degree. My final year project is about GIS (Geographical Information System). The title for this project is Equipment Management System for Paya Indah Wetlands. FYI, Paya Indah Wetlands is one of the recreation park in Malaysia. This system is to manage the schedule the use of equipments in this park using the map. So, here is the main screen for this system. This system I develop using PHP and Advance Javascript.



There are 3 users; admin, clerk and staff. This is the login screen for all users. It will differentiate by the role of each user. So here I just put the preview of my screen. Later I will explain more.


Tuesday 29 March 2011

Direct printing in C# windows application

Just wanna share with u all about the direct printing in the C# windows application. This is little bit tricky for me at first because there are so many things about printing in C# that I need to learn. So, here is my code for direct printing. You can design your report in rdlc.



private void Print_Click(object sender, EventArgs e)
{
BasePrint printForm = new BasePrint();
                ReportDataSource reportDataSource = new ReportDataSource();


                printForm.Report.Reset();
                printForm.Report.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                reportDataSource.Name = "General_PPT_pptAcception"; <--link to the object for data (the  namespace: General.PPT.pptAcception


                DataTable dt = Util.ConvertDataTable(pptTerima);
                reportDataSource.Value = dt;


                ReportViewer ReportViewer = new ReportViewer();


                ReportViewer.LocalReport.DataSources.Clear();        
                  
                ReportViewer.LocalReport.ReportEmbeddedResource = "PrintForm.rdlc";
         
                ReportViewer.LocalReport.DataSources.Add(reportDataSource);


                Export(ReportViewer.LocalReport);


                Print(Convert.ToInt16(Copy.Text.Trim())); <--number of copy


}


Also include all this code:



    #region direct printing
        public void Dispose()
        {
            if (m_streams != null)
            {
                foreach (Stream stream in m_streams)
                    stream.Close();
                m_streams = null;
            }
        }


        private Stream CreateStream(string name,
      string fileNameExtension, Encoding encoding,
      string mimeType, bool willSeek)
        {
            Stream stream = new MemoryStream();
            m_streams.Add(stream);
            return stream;
        }
        // Export the given report as an EMF (Enhanced Metafile) file.
        private void Export(LocalReport report)
        {
            string deviceInfo =
              @"<DeviceInfo>
                <OutputFormat>EMF</OutputFormat>
                <PageWidth>210mm</PageWidth>
                <PageHeight>280mm</PageHeight>
                <MarginTop>0.1in</MarginTop>
                <MarginLeft>0in</MarginLeft>
                <MarginRight>0in</MarginRight>
                <MarginBottom>0in</MarginBottom>
            </DeviceInfo>";
            Warning[] warnings;
            m_streams = new List<Stream>();
            report.Render("Image", deviceInfo, CreateStream,
               out warnings);
            foreach (Stream stream in m_streams)
                stream.Position = 0;
        }
        // Handler for PrintPageEvents
        private void PrintPage(object sender, PrintPageEventArgs ev)
        {
            Metafile pageImage = new
               Metafile(m_streams[m_currentPageIndex]);


            // Adjust rectangular area with printer margins.
            Rectangle adjustedRect = new Rectangle(
                ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX,
                ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY,
                ev.PageBounds.Width,
                ev.PageBounds.Height);


            // Draw a white background for the report
            ev.Graphics.FillRectangle(Brushes.White, adjustedRect);


            // Draw the report content
            ev.Graphics.DrawImage(pageImage, adjustedRect);


            // Prepare for the next page. Make sure we haven't hit the end.
            m_currentPageIndex++;
            ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
        }


        private void Print(short pages)
        {
            if (m_streams == null || m_streams.Count == 0)
                throw new Exception("Error: no stream to print.");
            PrintDocument printDoc = new PrintDocument();
            printDoc.PrinterSettings.Copies = pages;
            if (!printDoc.PrinterSettings.IsValid)
            {
                throw new Exception("Error: cannot find the default printer.");
            }
            else
            {
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                m_currentPageIndex = 0;
                printDoc.Print();
            }
        }


        #endregion

GDI+ error in C# giving me headache

I already spend almost the 3 hours to solve this error for converting the image to string in C#. At last, I already find the solution. I need to store the image from the picture box to image object before converting to string and save it to local first to prevent this GDI+ error. This is my code:





Image imgMAD = pictureBox1.Image;

 Bitmap bp = new Bitmap(imgMAD);
 bp.Save("Image.jpg");


String strImg = Util.ConvertImageToString("Image.jpg");


bp.Dispose();
              





This is the function to convert image to string:


 public static string ConvertImageToString(string s_ImgPath)
{
            Image img = Image.FromFile(s_ImgPath);
            return Base64ImageToString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
 }

My career as Software Developer

Hi, this is my first blog after planning to have blog since 3 years ago :)
So, I will just share my experience as Software Developer. I just finish my study in Information System Engineering in local university in Malaysia during June 2010. I start my career in one local software house company since July 2010 as Software Developer. My position require me to use .NET and C# to develop windows application and using Java as middleware to connect with DB2 database. .NET is new for me because during my study, I just familiar with Java, PHP, HTML, CSS and C++. I learn everything myself. Almost all I learn from internet and start develop the simple things first, like GUI using C#.

Want advise from u all about blogging :)