コード例 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //Bitmap map;
     if (Request["chartImg"] != null && Request["chartType"] != null && Request["tableData"] != null && Request["source"] != null && Request["keywords"] != null && Request["title"] != null && Request["subtitle"] != null && Request["filename"] != null)
     {
         string imageBitString = Request["chartImg"].ToString();
         string imageType = Request["chartType"].ToString();
         string tTableData = Request["tableData"].ToString();
         string tSource = Request["source"].ToString();
         string tKeywords = Request["keywords"].ToString();
         string tTitle = Request["title"].ToString();
         string tSubtitle = Request["subtitle"].ToString();
         string tfilename = Request["filename"].ToString();
         if (String.IsNullOrEmpty(tfilename))
             tfilename = "radar";
         string extenstion =string.Empty;
         string contentType = string.Empty;
         MemoryStream tData = null;
         switch(imageType.ToLower())
         {
             case "image/png":
                 tData = new MemoryStream();
                 MemoryStream picStream = new MemoryStream(Convert.FromBase64String(imageBitString));
                 extenstion = ".png";
                 contentType = "image/png";
                 tData = picStream;
                 picStream.Close();
                 picStream.Dispose();
                 break;
             case "application/vnd.xls":
                 tData = new MemoryStream();
                 Callback callbackObj = new Callback(this.Page);
                 IWorkbook workbook = callbackObj.getWorkbookForSwf(tTitle, tSubtitle, tSource, tKeywords, tTableData, imageBitString);
                 if (workbook!=null)
                     workbook.SaveToStream(tData, FileFormat.XLS97);
                 else
                     workbook.SaveToStream(tData, FileFormat.XLS97);
                 workbook.Close();
                 extenstion = ".xls";
                 contentType = "application/vnd.xls";
                 break;
         }
         tData.Close();
         tData.Dispose();
         Response.ClearContent();
         Response.ClearHeaders();
         Response.ContentType = contentType;
         Response.AppendHeader("Content-Disposition", "attachment; filename=" + tfilename + extenstion +"");
         Response.BinaryWrite(tData.ToArray());
         Response.End();
     }
 }
コード例 #2
0
    public string SaveGalleryItem(string requestParam)
    {
        string RetVal;
        string[] Params;
        string DBNId, LngCode, imgInText = string.Empty, UserNId, CategoryNId, Indicators,IndicatorNids, Areas, UDK, Name, Desc, Type, ChartType, SettingData = string.Empty, folderStructure = "stock\\Gallery\\", title = string.Empty, subtitle = string.Empty, source = string.Empty, keywords = string.Empty, tableData = string.Empty;
        string KeyWordNIds, SelAreaInQds,dbLngCode=string.Empty;

        RetVal = string.Empty;

        try
        {
            Params = requestParam.Split(new string[] { Constants.Delimiters.ParamDelimiter }, StringSplitOptions.None);
            DBNId = Params[0].Trim();
            LngCode = Params[1].Trim();
            UserNId = Params[2].Trim();
            CategoryNId = Params[3].Trim();
            IndicatorNids = Params[4].Trim();
            Indicators = getIndicatorNames(getIndicatorNameDataTable(IndicatorNids, Int32.Parse(DBNId), LngCode));
            Areas = Params[5].Trim();
            UDK = Params[6].Trim();
            Name = Params[7].Trim();
            Desc = Params[8].Trim();
            Type = Params[9].Trim();
            ChartType = Params[10].Trim();
            SelAreaInQds = Params[11].Trim();
            #region Making folder structure
            if (isUserAdmin(UserNId))
                folderStructure += "public\\admin\\";
            else
                folderStructure += "private\\" + UserNId + "\\";
            #endregion
            #region In case of graph and table
            if (Type.ToLower() == "g" || Type.ToLower() == "t")
            {
                imgInText = Params[12].Trim();
                SettingData = Params[13].Trim();
                title = Params[14].Trim();
                subtitle = Params[15].Trim();
                source = Params[16].Trim();
                keywords = Params[17].Trim();
                tableData = Params[18].Trim();
            }
            #endregion
            // Reading XML to read block  {@@}
            dbLngCode = Global.GetDefaultLanguageCodeDB(DBNId.ToString(), LngCode);
            int IntResult;

            string Query = string.Empty;
            DataTable DtPresentation;
            DIConnection DIConnection = null;
            DIConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, Server.MapPath("~//stock//Database.mdb"),
                           string.Empty, string.Empty);
            Query = "SELECT * from presentations WHERE pres_name ='" + DevInfo.Lib.DI_LibBAL.Utility.DICommon.RemoveQuotes(Name) + "' AND user_nid =" + UserNId;
            DtPresentation = DIConnection.ExecuteDataTable(Query);
            if (DtPresentation.Rows.Count > 0)
            {
                RetVal = "-999";
            }
            else
            {
                if (!Int32.TryParse(SelAreaInQds, out IntResult))
                {
                    XmlDocument BlockDoc = new XmlDocument();
                    string BlockCodeListPath = HttpContext.Current.Request.PhysicalApplicationPath + "stock\\data\\" + DBNId + "\\ds\\" + LngCode;
                    if (Directory.Exists(HttpContext.Current.Request.PhysicalApplicationPath + "stock\\data\\" + DBNId + "\\ds\\" + LngCode))
                    {
                        BlockCodeListPath += "\\area\\qscodelist.xml";
                    }
                    else
                    {
                        BlockCodeListPath = HttpContext.Current.Request.PhysicalApplicationPath + "stock\\data\\" + DBNId + "\\ds\\" + dbLngCode + "\\area\\qscodelist.xml";
                    }
                    BlockDoc.Load(BlockCodeListPath);
                    XmlNodeList aTags = BlockDoc.GetElementsByTagName("a");
                    foreach (XmlNode aTag in aTags)
                    {
                        if (aTag.Attributes["nid"].Value == SelAreaInQds)
                        {
                            Areas += "{@@}" + aTag.Attributes["n"].Value;
                            break;
                        }
                    }
                }
                else
                {
                    List<System.Data.Common.DbParameter> DbParams = new List<System.Data.Common.DbParameter>();
                    DIConnection ObjDIConnection = this.GetDbConnection(int.Parse(DBNId));
                    System.Data.Common.DbParameter Param1 = ObjDIConnection.CreateDBParameter();
                    Param1.ParameterName = "AreaNids";
                    Param1.DbType = DbType.String;
                    Param1.Value = SelAreaInQds;
                    DbParams.Add(Param1);

                    DataTable dtAreaNames = ObjDIConnection.ExecuteDataTable("sp_get_AreaNames_" + dbLngCode, CommandType.StoredProcedure, DbParams);
                    if (dtAreaNames != null && dtAreaNames.Rows.Count > 0)
                    {
                        Areas += "{@@}" + dtAreaNames.Rows[0][0].ToString();
                    }
                }
                // Insert records into database
                KeyWordNIds = this.InsertIntoKeywordsTable(Indicators, Areas, UDK);
                //RetVal = this.InsertIntoPresentationsTable(DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString(), CategoryNId, Name, Type,
                //                                            ChartType, Desc, UDK, DBNId, LngCode, UserNId, KeyWordNIds);
                RetVal = this.InsertIntoPresentationsTable(DateTime.Now.ToString(), DateTime.Now.ToString(), CategoryNId, Name, Type,
                                                            ChartType, Desc, UDK, DBNId, LngCode, UserNId, KeyWordNIds);
                // Created Folder if not exists
                this.Create_Directory_If_Not_Exists(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal));
                #region Save details for radar
                if (ChartType == "radar" || ChartType == "scatter3d")
                {
                    MemoryStream picStream = new MemoryStream(Convert.FromBase64String(imgInText));
                    System.Drawing.Image chartImage = System.Drawing.Image.FromStream(picStream);
                    Bitmap bmp = new Bitmap(chartImage, 269, 150);
                    bmp.Save(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + "_t.png"), System.Drawing.Imaging.ImageFormat.Png);
                    bmp.Dispose();
                    bmp = new Bitmap(chartImage, 584, 326);
                    bmp.Save(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"), System.Drawing.Imaging.ImageFormat.Png);
                    bmp.Dispose();
                    chartImage.Dispose();
                    this.Create_File(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\swfvisualizer.html"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".html"));
                    this.Save_Settings_File(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".xml"), SettingData);
                    Callback callbackObj = new Callback(this.Page);
                    IWorkbook workbook = callbackObj.getWorkbookForSwf(title, subtitle, source, keywords, tableData, imgInText);
                    workbook.SaveAs(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".xls"), SpreadsheetGear.FileFormat.XLS97);
                    workbook.Close();
                }
                #endregion
                #region Save details for Map
                else if (ChartType == "map")
                {
                    SaveKMLMap(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal), RetVal);
                    SavePngMap(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal), RetVal + "_t", false, false, 150, 269);
                    SavePngMap(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal), RetVal, true, true, 326, 584);
                    SaveExcelMap(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal), RetVal);
                    //SaveMap(string FolderNameWPath, string FileName)
                }
                #endregion
                #region Save details for table
                else if (ChartType == "table")
                {
                    this.Create_File(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\table.png"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"));
                    this.Create_File(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\table_t.png"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + "_t.png"));
                    Callback callbackObj = new Callback(this.Page);
                    IWorkbook workbook = callbackObj.getWorkbookXLS(title, subtitle, source, keywords, tableData, imgInText);
                    workbook.SaveAs(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".xls"), FileFormat.XLS97);
                    workbook.Close();
                    SettingData = SettingData.Replace("[******]", "[****]");
                    WriteHTMLtoFile(SettingData, Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".html"));

                }
                #endregion
                #region Save details for treemap
                else if (ChartType == "treemap" || ChartType == "cloud")
                {
                    string thumbImage = string.Empty;
                    string bigImage = string.Empty;
                    if (ChartType == "treemap")
                    {
                        thumbImage = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\treemap_t.png");
                        bigImage = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\treemap.png");
                    }
                    else
                    {
                        thumbImage = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\cloud_t.png");
                        bigImage = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\cloud.png");
                    }
                    this.Create_File(bigImage, Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"));
                    this.Create_File(thumbImage, Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + "_t.png"));
                    Callback callbackObj = new Callback(this.Page);
                    IWorkbook workbook = callbackObj.getWorkbookXLS(title, subtitle, source, keywords, tableData, imgInText);
                    workbook.SaveAs(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".xls"), SpreadsheetGear.FileFormat.XLS97);
                    workbook.Close();

                    this.Save_Settings_File(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".xml"), SettingData);
                    File.WriteAllText(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".html"), imgInText);
                }
                #endregion
                #region Save details for other visualizer callforsvg_rasterizer
                else
                {
                    Process dosProcess = new Process();
                    string svg_folder = "libraries\\svg_rasterizer\\";
                    string workingDir = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, svg_folder);
                    string filePath = Path.Combine(workingDir, RetVal + Constants.XLSDownloadType.SvgExtention);
                    FileStream fileStream = File.Create(filePath);
                    fileStream.Close();
                    using (StreamWriter sw = new StreamWriter(filePath))
                    {
                        sw.Write(imgInText);
                    }
                    string filePth = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @filePath);

                    var sampleDoc = SvgDocument.Open(filePth, new Dictionary<string, string>
                        {
                            {"entity1", "fill:red" },
                            {"entity2", "fill:yellow" }
                        });
                    string destination = @workingDir + "\\" + RetVal + ".png";
                    sampleDoc.Draw().Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, destination));

                    //string command = "/C java -jar " + Constants.XLSDownloadType.BatikRasterizerJarFile + " " + Constants.XLSDownloadType.ImageType + " " + RetVal + Constants.XLSDownloadType.SvgExtention;
                    //ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
                    //startInfo.UseShellExecute = false;
                    //startInfo.WorkingDirectory = workingDir;
                    //startInfo.Arguments = command;
                    //startInfo.CreateNoWindow = false;
                    //dosProcess.StartInfo = startInfo;
                    //dosProcess.Start();

                    //dosProcess.WaitForExit();
                    dosProcess.Close();
                    File.Move(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, svg_folder) + RetVal + ".png", Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"));
                    File.Move(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, svg_folder) + RetVal + ".svg", Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".svg"));
                    SaveThumbnail(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + "_t.png"), 150, 150);
                    File.Copy(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + "t.png"), true);

                    File.Delete(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"));
                    SaveThumbnail(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + "t.png"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".png"), 698, 326);

                    this.Save_Settings_File(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".xml"), SettingData);
                    this.Create_File(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\visualizer.html"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".html"));
                    Callback callbackObj = new Callback(this.Page);
                    IWorkbook workbook = callbackObj.getWorkbookXLS(title, subtitle, source, keywords, tableData, imgInText);
                    workbook.SaveAs(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, folderStructure + RetVal + "\\" + RetVal + ".xls"), SpreadsheetGear.FileFormat.XLS97);
                    workbook.Close();
                }
                #endregion
            }
        }
        catch (Exception ex)
        {
            RetVal = ex.Message;
            Global.CreateExceptionString(ex, null);
        }

        return RetVal;
    }