コード例 #1
0
        protected int GetCreativeWidth(int format)
        {
            var width = 100;

            if (AsyncFileUpload1.HasFile)
            {
                if (format == 0)
                {
                    try
                    {
                        System.Drawing.Image I = System.Drawing.Image.FromStream(AsyncFileUpload1.PostedFile.InputStream);
                        width = I.Width;
                    }
                    catch (Exception)
                    {
                       width = 100;
                    }
                }

                if (format == 1)
                {
                    try
                    {
                        var swfParser = new SwfParser();
                        Rectangle = swfParser.GetDimensions(AsyncFileUpload1.PostedFile.InputStream);
                        width = Rectangle.Width;
                    }
                    catch (Exception)
                    {
                        width = 100;
                    }

                }

            }
            return width;
        }
コード例 #2
0
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "alpha" || e.CommandName == "NoFilter")
        {
            String value = null;
            switch (e.CommandName)
            {
            case ("alpha"):
            {
                value = string.Format("{0}%", e.CommandArgument);
                break;
            }

            case ("NoFilter"):
            {
                value = "%";
                break;
            }
            }
            ObjectDataSource1.SelectParameters["CompanyName"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string AdsBannerID, Priority, IsAvailable;
            var    oAdsBanner = new AdsBanner();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                AdsBannerID = item.GetDataKeyValue("AdsBannerID").ToString();
                Priority    = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oAdsBanner.AdsBannerQuickUpdate(
                    AdsBannerID,
                    Priority,
                    IsAvailable
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oAdsBanner = new AdsBanner();

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                string strFileName = ((HiddenField)item.FindControl("hdnFileName")).Value;

                if (!string.IsNullOrEmpty(strFileName))
                {
                    string strSavePath = Server.MapPath("~/res/advertisement/" + strFileName);
                    if (File.Exists(strSavePath))
                    {
                        File.Delete(strSavePath);
                    }
                }
            }
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command      = e.CommandName;
            var row          = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileFileName = (RadUpload)row.FindControl("FileFileName");
            var dpFromDate   = (RadDatePicker)row.FindControl("dpFromDate");
            var dpToDate     = (RadDatePicker)row.FindControl("dpToDate");

            string strCompanyName = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtCompanyName")).Content.Trim()));//((TextBox)row.FindControl("txtCompanyName")).Text.Trim();
            //string strTitle = ((TextBox)row.FindControl("txtTitle")).Text.Trim();
            //string strDescription = ((TextBox)row.FindControl("txtDescription")).Text.Trim();
            string strConvertedAdsBannerName = Common.ConvertTitle(strCompanyName);
            string strFileName      = FileFileName.UploadedFiles.Count > 0 ? FileFileName.UploadedFiles[0].GetName() : "";
            string strIsAvailable   = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strPriority      = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();
            string strFromDate      = dpFromDate.SelectedDate.HasValue ? dpFromDate.SelectedDate.Value.ToString("MM/dd/yyyy") : "";
            string strToDate        = dpToDate.SelectedDate.HasValue ? dpToDate.SelectedDate.Value.ToString("MM/dd/yyyy") : "";
            string strAdsCategoryID = "8";// ((RadComboBox)row.FindControl("ddlCategory")).SelectedValue;
            string strWebsite       = ((TextBox)row.FindControl("txtWebsite")).Text.Trim();
            double ratio            = 0;

            if (!string.IsNullOrEmpty(strFileName))
            {
                string strTempPath = Server.MapPath(FileFileName.TargetFolder + strFileName);
                if (IsImageFormat(strFileName))
                {
                    System.Drawing.Image img = System.Drawing.Image.FromFile(strTempPath);
                    ratio = (double)img.Width / (img.Height == 0 ? 1 : img.Height);
                    img.Dispose();
                }
                else
                {
                    SwfParser swfParser = new SwfParser();
                    Rectangle rectangle = swfParser.GetDimensions(strTempPath);
                    ratio = (double)rectangle.Width / (rectangle.Height == 0 ? 1 : rectangle.Height);
                }
                string[] files = Directory.GetFiles(Server.MapPath(FileFileName.TargetFolder));

                foreach (string filePath in files)
                {
                    File.Delete(filePath);
                }
            }

            var oAdsBanner = new AdsBanner();

            if (e.CommandName == "PerformInsert")
            {
                strFileName = oAdsBanner.AdsBannerInsert(
                    strFileName,
                    strConvertedAdsBannerName,
                    strAdsCategoryID,
                    strCompanyName,
                    strWebsite,
                    strFromDate,
                    strToDate,
                    strPriority,
                    strIsAvailable,
                    ratio == 0 ? "" : ratio.ToString().Replace(',', '.')
                    );

                string strFullPath = "~/res/advertisement/" + strFileName;

                if (!string.IsNullOrEmpty(strFileName))
                {
                    FileFileName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    if (IsImageFormat(strFileName))
                    {
                        //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    }
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam   = ObjectDataSource1.UpdateParameters;
                var strAdsBannerID  = row.GetDataKeyValue("AdsBannerID").ToString();
                var strOldFileName  = ((HiddenField)row.FindControl("hdnFileName")).Value;
                var strOldImagePath = Server.MapPath("~/res/advertisement/" + strOldFileName);

                dsUpdateParam["FileName"].DefaultValue = strFileName;
                dsUpdateParam["ConvertedAdsBannerName"].DefaultValue = strConvertedAdsBannerName;
                dsUpdateParam["AdsCategoryID"].DefaultValue          = strAdsCategoryID;
                dsUpdateParam["FromDate"].DefaultValue    = strFromDate;
                dsUpdateParam["ToDate"].DefaultValue      = strToDate;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;
                dsUpdateParam["Ratio"].DefaultValue       = ratio == 0 ? "" : ratio.ToString().Replace(',', '.');

                if (!string.IsNullOrEmpty(strFileName))
                {
                    var strFullPath = "~/res/advertisement/" + (string.IsNullOrEmpty(strConvertedAdsBannerName) ? "" : strConvertedAdsBannerName + "-") + strAdsBannerID + strFileName.Substring(strFileName.LastIndexOf('.'));

                    if (File.Exists(strOldImagePath))
                    {
                        File.Delete(strOldImagePath);
                    }

                    FileFileName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    if (IsImageFormat(strFileName))
                    {
                        //ResizeCropImage.ResizeByCondition(strFullPath, 654, 654);
                    }
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oAdsBanner     = new AdsBanner();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strAdsBannerID = s[0];
            var strFileName    = s[1];

            oAdsBanner.AdsBannerDelete(strAdsBannerID);
            DeleteImage(strFileName);
            RadGrid1.Rebind();
        }
    }
コード例 #3
0
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "alpha" || e.CommandName == "NoFilter")
        {
            String value = null;
            switch (e.CommandName)
            {
                case ("alpha"):
                    {
                        value = string.Format("{0}%", e.CommandArgument);
                        break;
                    }
                case ("NoFilter"):
                    {
                        value = "%";
                        break;
                    }
            }
            ObjectDataSource1.SelectParameters["CompanyName"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string AdsBannerID, Priority, IsAvailable;
            var oAdsBanner = new AdsBanner();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                AdsBannerID = item.GetDataKeyValue("AdsBannerID").ToString();
                Priority = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oAdsBanner.AdsBannerQuickUpdate(
                    AdsBannerID,
                    Priority,
                    IsAvailable
                );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oAdsBanner = new AdsBanner();

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                string strFileName = ((HiddenField)item.FindControl("hdnFileName")).Value;

                if (!string.IsNullOrEmpty(strFileName))
                {
                    string strSavePath = Server.MapPath("~/res/advertisement/" + strFileName);
                    if (File.Exists(strSavePath))
                        File.Delete(strSavePath);
                }
            }
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command = e.CommandName;
            var row = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileFileName = (RadUpload)row.FindControl("FileFileName");
            var dpFromDate = (RadDatePicker)row.FindControl("dpFromDate");
            var dpToDate = (RadDatePicker)row.FindControl("dpToDate");

            string strCompanyName = ((TextBox)row.FindControl("txtCompanyName")).Text.Trim();
            string strConvertedAdsBannerName = Common.ConvertTitle(strCompanyName);
            string strFileName = FileFileName.UploadedFiles.Count > 0 ? FileFileName.UploadedFiles[0].GetName() : "";
            string strIsAvailable = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strPriority = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();
            string strFromDate = dpFromDate.SelectedDate.HasValue ? dpFromDate.SelectedDate.Value.ToString("MM/dd/yyyy") : "";
            string strToDate = dpToDate.SelectedDate.HasValue ? dpToDate.SelectedDate.Value.ToString("MM/dd/yyyy") : "";
            string strAdsCategoryID = "5";//((RadComboBox)row.FindControl("ddlCategory")).SelectedValue;
            string strWebsite = ((TextBox)row.FindControl("txtWebsite")).Text.Trim();
            double ratio = 0;

            if (!string.IsNullOrEmpty(strFileName))
            {
                string strTempPath = Server.MapPath(FileFileName.TargetFolder + strFileName);
                if (IsImageFormat(strFileName))
                {
                    System.Drawing.Image img = System.Drawing.Image.FromFile(strTempPath);
                    ratio = (double)img.Width / (img.Height == 0 ? 1 : img.Height);
                    img.Dispose();
                }
                else
                {
                    SwfParser swfParser = new SwfParser();
                    Rectangle rectangle = swfParser.GetDimensions(strTempPath);
                    ratio = (double)rectangle.Width / (rectangle.Height == 0 ? 1 : rectangle.Height);
                }
                string[] files = Directory.GetFiles(Server.MapPath(FileFileName.TargetFolder));

                foreach (string filePath in files)
                    File.Delete(filePath);
            }

            var oAdsBanner = new AdsBanner();

            if (e.CommandName == "PerformInsert")
            {
                strFileName = oAdsBanner.AdsBannerInsert(
                    strFileName,
                    strConvertedAdsBannerName,
                    strAdsCategoryID,
                    strCompanyName,
                    strWebsite,
                    strFromDate,
                    strToDate,
                    strPriority,
                    strIsAvailable,
                    ratio == 0 ? "" : ratio.ToString().Replace(',', '.')
                    );

                string strFullPath = "~/res/advertisement/" + strFileName;

                if (!string.IsNullOrEmpty(strFileName))
                {
                    FileFileName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    if (IsImageFormat(strFileName))
                    {
                        //ResizeCropImage.ResizeByCondition(strFullPath, 935, 420);
                    }
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam = ObjectDataSource1.UpdateParameters;
                var strAdsBannerID = row.GetDataKeyValue("AdsBannerID").ToString();
                var strOldFileName = ((HiddenField)row.FindControl("hdnFileName")).Value;
                var strOldImagePath = Server.MapPath("~/res/advertisement/" + strOldFileName);

                dsUpdateParam["FileName"].DefaultValue = strFileName;
                dsUpdateParam["ConvertedAdsBannerName"].DefaultValue = strConvertedAdsBannerName;
                dsUpdateParam["AdsCategoryID"].DefaultValue = strAdsCategoryID;
                dsUpdateParam["FromDate"].DefaultValue = strFromDate;
                dsUpdateParam["ToDate"].DefaultValue = strToDate;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;
                dsUpdateParam["Ratio"].DefaultValue = ratio == 0 ? "" : ratio.ToString().Replace(',', '.');

                if (!string.IsNullOrEmpty(strFileName))
                {
                    var strFullPath = "~/res/advertisement/" + (string.IsNullOrEmpty(strConvertedAdsBannerName) ? "" : strConvertedAdsBannerName + "-") + strAdsBannerID + strFileName.Substring(strFileName.LastIndexOf('.'));

                    if (File.Exists(strOldImagePath))
                        File.Delete(strOldImagePath);

                    FileFileName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    if (IsImageFormat(strFileName))
                    {
                        //ResizeCropImage.ResizeByCondition(strFullPath, 935, 420);
                    }
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oAdsBanner = new AdsBanner();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strAdsBannerID = s[0];
            var strFileName = s[1];

            oAdsBanner.AdsBannerDelete(strAdsBannerID);
            DeleteImage(strFileName);
            RadGrid1.Rebind();
        }
    }
コード例 #4
0
        private void TabExtract_DragDrop(object sender, DragEventArgs e)
        {
            bool mapAnalysis = false;


            string filename = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];

            try {
                SwfParser swf = new SwfParser();
                swf.Parse(filename);


                foreach (var img in swf.FindTags <ImageTag>())
                {
                    img.ExtractImage().Save(img.CharacterID + ".png", System.Drawing.Imaging.ImageFormat.Png);
                }

                foreach (var sound in swf.FindTags <DefineSound>())
                {
                    using (var writer = new FileStream(sound.CharacterID + sound.GetFileExtension(), FileMode.Create, FileAccess.Write, FileShare.Write)) {
                        var dat = sound.ExtractSound();
                        writer.Write(dat, 0, dat.Length);
                    }
                }



                if (mapAnalysis)                        // kancolle mapdata analysis

                {
                    var    imagetags = swf.FindTags <ImageTag>();
                    Bitmap map       = new Bitmap(768, 435);
                    bool   loaded    = false;

                    using (var g = Graphics.FromImage(map)) {
                        foreach (var it in imagetags)
                        {
                            var img = it.ExtractImage();
                            if (img.Width == map.Width && img.Height == map.Height)
                            {
                                g.DrawImage(img, 0, 0);
                                loaded = true;
                            }
                            img.Dispose();
                        }

                        if (!loaded)
                        {
                            throw new InvalidOperationException("this data is not map");
                        }



                        var placeobjects = swf.FindTags <PlaceObject2>();

                        for (int i = 0; ; i++)
                        {
                            string name = "line" + i;

                            var linetag = placeobjects.FirstOrDefault(t => t.HasName && t.Name == name);

                            if (linetag == null)
                            {
                                break;
                            }

                            var pos = new PointF(linetag.Matrix.TranslateX, linetag.Matrix.TranslateY);

                            if (pos.X < 0)
                            {
                                pos.X = 0;
                            }
                            else if (pos.X >= map.Width)
                            {
                                pos.X = map.Width - 1;
                            }
                            if (pos.Y < 0)
                            {
                                pos.Y = 0;
                            }
                            else if (pos.Y >= map.Height)
                            {
                                pos.Y = map.Height - 1;
                            }

                            map.SetPixel((int)pos.X, (int)pos.Y, Color.Black);
                            g.DrawString(i.ToString(), Font, Brushes.White, new PointF(pos.X + 1, pos.Y + 1));
                            g.DrawString(i.ToString(), Font, Brushes.Black, pos);

                            var parentSprite = swf.FindTags <DefineSprite>().FirstOrDefault(t => t.CharacterID == linetag.CharacterID);
                            if (parentSprite != null)
                            {
                                var innerplace = parentSprite.FindTags <PlaceObject2>().FirstOrDefault();
                                if (innerplace != null)
                                {
                                    var shape = swf.FindTags <DefineShape>().FirstOrDefault(t => t.CharacterID == innerplace.CharacterID);
                                    if (shape != null)
                                    {
                                        var rect = shape.Bounds.ToPositiveRectangle();
                                        g.DrawRectangle(Pens.Orange, linetag.Matrix.TranslateX + rect.X, linetag.Matrix.TranslateY + rect.Y, rect.Width, rect.Height);
                                    }
                                }
                            }
                        }
                    }

                    if (pictureBox1.Image != null)
                    {
                        var img = pictureBox1.Image;
                        pictureBox1.Image = null;
                        img.Dispose();
                    }
                    pictureBox1.Image = map;
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }