예제 #1
0
        public string CompanyLogoImageFileName(string CompanyID, CompanyImageTypes CompanyImageType, string ConnectionString)
        {
            ServiceCallDataElements.SQLServer sqlServer = new ServiceCallDataElements.SQLServer();
            string sImageFile = ""; string sName = ""; string sTypeColumn = ""; string sExtention = ""; string sTempPath = "";

            try
            {
                sTempPath = Environment.CurrentDirectory + "\\Temp\\";

                switch (CompanyImageType)
                {
                case CompanyImageTypes.InvoiceLogoImage:
                    sTypeColumn = "InvoiceLogoImageType";
                    sName       = "InvoiceLogo";
                    break;

                case CompanyImageTypes.SmallLogoImage:
                    sTypeColumn = "SmallLogoImageType";
                    sName       = "SmallLogo";
                    break;
                }

                sqlServer.ConnectionString = ConnectionString;

                sExtention = sqlServer.GetStringValue("SELECT " + sTypeColumn + " FROM Core.Companies WHERE CompanyID='" + CompanyID + "'", "");

                if (sExtention == "")
                {
                    sExtention = "jpg";
                }

                sImageFile = sTempPath + sName + "_" + CompanyID + "." + sExtention;
            }
            catch (Exception ex)
            {
                sImageFile = "";
            }

            return(sImageFile);
        }
예제 #2
0
        public bool ExtractCompanyImage(string CompanyID, ref string LogoImageFile, CompanyImageTypes CompanyImageType, string ConnectionString)
        {
            System.IO.FileStream  DocumentStream;
            System.Data.DataTable DataTable = null; System.Data.DataRow DataRow = null;
            string sCommandText = ""; string sImageColumn = ""; string sImageSizeColumn = "";
            int    iFileSize = 0; bool bResult = true;

            ServiceCallDataElements.SQLServer SQLServer = new ServiceCallDataElements.SQLServer();

            try
            {
                switch (CompanyImageType)
                {
                case CompanyImageTypes.InvoiceLogoImage:
                    sImageColumn     = "InvoiceLogoImage";
                    sImageSizeColumn = "InvoiceLogoImageSize";
                    break;

                case CompanyImageTypes.SmallLogoImage:
                    sImageColumn     = "SmallLogoImage";
                    sImageSizeColumn = "SmallLogoImageSize";
                    break;
                }

                RemoveFile(LogoImageFile);

                sCommandText = "SELECT " + sImageColumn + "," + sImageSizeColumn + " FROM Core.Companies WHERE CompanyID='" + CompanyID + "'";

                SQLServer.ConnectionString = ConnectionString;

                DataTable = SQLServer.GetDataTable(sCommandText);

                DataTable.TableName = "Logo";

                DataRow = DataTable.Rows[0];

                iFileSize = Convert.ToInt32(DataRow[sImageSizeColumn]);

                Byte[] BLOBData = new Byte[iFileSize - 1];

                BLOBData = (Byte[])DataRow[sImageColumn];

                DocumentStream = new System.IO.FileStream(LogoImageFile, System.IO.FileMode.CreateNew);

                DocumentStream.Write(BLOBData, 0, iFileSize);
                DocumentStream.Flush();
                DocumentStream.Close();

                DocumentStream = null;
            }
            catch (Exception ex)
            {
                bResult = false;
                Console.WriteLine(ex.Message);
            }
            finally
            {
                DocumentStream = null;
                DataTable      = null;
            }

            return(bResult);
        }