⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucformatsetting.ascx.cs

📁 在线 图书网上购物系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControls_ucFormatSetting : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //设置字体
            Utilities.BindingDropDownList(this.ddlFontFamily, Utilities.GetFontsName());
            //设置Times New Roman为默认选择项
            Utilities.SetSelectDropDownListByDisplayMember(this.ddlFontFamily, "Times New Roman");
            //显示已设置的页面格式
            LoadPageStyle();
            //显示已设置的正文格式
            LoadParagraphStyleByNameLocal(ddlNameLocal.SelectedValue);
        }
    }
        
    protected void btnPapagraphSubmit_Click(object sender, EventArgs e)
    {
        //提交段落格式
        DataTable dt = Global.GetFieldsFromTablesByCondiction("*","ParagraphStyle","NameLocal like '" + this.ddlNameLocal.SelectedValue + "'");
        //段落中已有记录,则更新,否则插入
        if (dt.Rows.Count == 0)
        {
            InsertParagraphStyle();
        }
        else
        {
            UpdateParagraphStyle();
        }
    }
    protected void btnPageSubmit_Click(object sender, EventArgs e)
    {
        //提交页面设置,若已有记录,则先删除,再插入
        DataTable dt = Global.GetFieldsFromTablesByCondiction("*", "PageStyle", "");
        if (dt.Rows.Count != 0)
        {
            PageStyle.Delete();
        }  
        InsertPageStyle();
        
    }
    #region InsertParagraphStyle
    private void InsertParagraphStyle()
    {
        ParagraphStyle para = new ParagraphStyle();
        para.Italic = this.cbItalic.Checked;
        para.Bold = this.cbBold.Checked;
        para.NameLocal = this.ddlNameLocal.SelectedValue;
        para.FontSize = double.Parse(this.ddlFontSize.SelectedValue);
        para.LineSpacingRule = this.ddlLineSpacingRule.SelectedValue;
        para.FontName = this.ddlFontFamily.SelectedValue;
    
        //行距为单,1.5,或2倍时,后面的行距的设置框为0
        //1行=12
        switch (para.LineSpacingRule)
        {
            case "wdLineSpace1pt5":
                para.LineSpacing = 18.0; break;
            case "wdLineSpaceDouble":
                para.LineSpacing = 24.0; break;
            case "wdLineSpaceSingle":
                para.LineSpacing = 12.0; break;
            default:
                para.LineSpacing = 12.0 * double.Parse(this.tbLineSpacing.Text); break;
        }

        /********************************************************************************************
         * 有“行”时,则LineUnit**中为实际行数,且Space**中也有值,1行=15.6磅
         * 若有“磅”时,LineUnit**为0,Space**中为实际的磅数
         ******************************************************************************************/
        if (this.tbSpaceAfter.Text.IndexOf("磅") != -1)//有磅时,LiueUnit**为0,Space**中为实际的磅数
        {
            string temp = this.tbSpaceAfter.Text.Trim();
            temp = temp.Substring(0, temp.LastIndexOf("磅")).Trim();
           
            para.SpaceAfter = double.Parse(temp);
            para.LineUnitAfter = 0.0;
        }
        else//是行数时,LineUnit**中为实际行数,且Space**中的值为 LineUnit** * 15.6
        {
            para.LineUnitAfter = double.Parse(this.tbSpaceAfter.Text);
            para.SpaceAfter = double.Parse(this.tbSpaceAfter.Text) * 15.6;//换算单位为15.6
        }

        if (this.tbSpaceBefore.Text.IndexOf("磅") != -1)//有磅时,LiueUnit**为0,Space**中为实际的磅数
        {
            string temp = this.tbSpaceBefore.Text.Trim();
            temp = temp.Substring(0, temp.LastIndexOf("磅")).Trim();
           
            para.SpaceBefore = double.Parse(temp);
            para.LineUnitBefore = 0.0;
        }
        else//是行数时,LineUnit**中为实际行数,且Space**中的值为 LineUnit** * 15.6
        {
            para.LineUnitBefore = double.Parse(this.tbSpaceBefore.Text);
            para.SpaceBefore = double.Parse(this.tbSpaceBefore.Text) * 15.6;
        }

        para.RightIndent = double.Parse(this.tbRightIndent.Text) * 10.5;
        para.LeftIndent = double.Parse(this.tbLeftIndent.Text) * 10.5;
        para.CharacterUnitLeftIndent = double.Parse(this.tbLeftIndent.Text);//实际字符
        para.CharacterUnitRightIndent = double.Parse(this.tbRightIndent.Text);
        para.CharacterUnitFirstLineIndent = double.Parse(this.tbCharacterUnitFirstLineIndent.Text);
        para.Alignment = this.ddlAlignment.SelectedValue;
        if (ParagraphStyle.Insert(para) != -100)
        {
            this.lbMsg.Text = this.ddlNameLocal.SelectedValue + "的格式设置成功";
        }
        else
        {
            this.lbMsg.Text = this.ddlNameLocal.SelectedValue + "的格式设置失败";
        }
    }
    #endregion
    #region InsertPageStyle
    private void InsertPageStyle()
    {
        PageStyle ps = new PageStyle();
        double ratio = 0.035277777777777777777777777777778;
        ps.TopMargin = double.Parse(this.tbTopMargin.Text) / ratio;//将厘米换算成Word中的值
        ps.RightMargin = double.Parse(this.tbRightMargin.Text) / ratio;
        ps.LeftMargin = double.Parse(this.tbLeftMargin.Text) / ratio;
        ps.ButtomMargin = double.Parse(this.tbButtomMargin.Text) / ratio;
        ps.PageSize = this.ddlPageSize.SelectedValue;
        ps.PageWidth = double.Parse(this.tbPageWidth.Text) / ratio;
        ps.PageHeight = double.Parse(this.tbPageHeiht.Text) / ratio;
        ps.PageFooter = double.Parse(this.tbPageFooter.Text) / ratio;
        ps.PageHeader = double.Parse(this.tbPageHeader.Text) / ratio;
        ps.ColNum = int.Parse(this.tbColnum.Text);
        ps.VerticalAlignment = this.ddlVerticalAlignment.SelectedValue;
        ps.Gutter = double.Parse(this.tbGutter.Text) / ratio;
        ps.GutterPos = this.ddlGutterPos.SelectedValue;
        if (PageStyle.Insert(ps) != -100)
        {
            this.lbMsg2.Text = "页面格式设置成功";
        }
        else
        {
            this.lbMsg2.Text = "页面格式设置失败";
        }
    }
    #endregion
    #region UpdateParagraphStyle
    private void UpdateParagraphStyle()
    {
        int paragraphstyleid = ParagraphStyle.GetIDByNameLocal(this.ddlNameLocal.SelectedValue);
        ParagraphStyle para = ParagraphStyle.GetParagraphStyle(paragraphstyleid);
        para.Italic = this.cbItalic.Checked;
        para.Bold = this.cbBold.Checked;

        para.FontSize = double.Parse(this.ddlFontSize.SelectedValue);
        para.LineSpacingRule = this.ddlLineSpacingRule.SelectedValue;
        para.FontName = this.ddlFontFamily.SelectedValue;
        //Word.WdLineSpacing.wdLineSpaceAtLeast//.wdLineSpaceSingle

        switch (para.LineSpacingRule)
        {
            case "wdLineSpace1pt5":
                para.LineSpacing = 18.0; break;
            case "wdLineSpaceDouble":
                para.LineSpacing = 24.0; break;
            case "wdLineSpaceSingle":
                para.LineSpacing = 12.0; break;
            default:
                para.LineSpacing = 12.0 * double.Parse(this.tbLineSpacing.Text); break;
        }
     
        if (this.tbSpaceAfter.Text.IndexOf("磅") != -1)//有磅时,LiueUnit**为0,Space**中为实际的磅数
        {
            string temp = this.tbSpaceAfter.Text.Trim();
            temp = temp.Substring(0, temp.LastIndexOf("磅")).Trim();
           
            para.SpaceAfter = double.Parse(temp);
            para.LineUnitAfter = 0.0;
        }
        else//是行数时,LineUnit**中为实际行数,且Space**中的值为 LineUnit** * 15.6
        {
            string temp = this.tbSpaceAfter.Text;
            para.LineUnitAfter = double.Parse(temp);
            para.SpaceAfter = double.Parse(this.tbSpaceAfter.Text) * 15.6;
        }

        if (this.tbSpaceBefore.Text.IndexOf("磅") != -1)//有磅时,LiueUnit**为0,Space**中为实际的磅数
        {
            string temp = this.tbSpaceBefore.Text.Trim();
            temp = temp.Substring(0, temp.LastIndexOf("磅")).Trim();
            para.SpaceBefore = double.Parse(temp);
            para.LineUnitBefore = 0.0;
        }
        else//是行数时,LineUnit**中为实际行数,且Space**中的值为 LineUnit** * 15.6
        {
            string temp = this.tbSpaceBefore.Text.Trim();
            para.LineUnitBefore = double.Parse(temp);
            para.SpaceBefore = double.Parse(temp) * 15.6;
        }

        para.RightIndent = double.Parse(this.tbRightIndent.Text) * 10.5;
        para.LeftIndent = double.Parse(this.tbLeftIndent.Text) * 10.5;
        para.CharacterUnitLeftIndent = double.Parse(this.tbLeftIndent.Text);//实际字符
        para.CharacterUnitRightIndent = double.Parse(this.tbRightIndent.Text);
        para.CharacterUnitFirstLineIndent = double.Parse(this.tbCharacterUnitFirstLineIndent.Text);
        para.Alignment = this.ddlAlignment.SelectedValue;
        if (ParagraphStyle.update(para) != -100)
        {
            this.lbMsg.Text = this.ddlNameLocal.SelectedValue + "的格式更新成功";
        }
        else
        {
            this.lbMsg.Text = this.ddlNameLocal.SelectedValue + "的格式更新失败";
        }
        
    }
    #endregion
    #region LoadPageStyle
    private void LoadPageStyle()
    {
        DataTable dt = Global.GetFieldsFromTablesByCondiction("*", "PageStyle", "");
        if (dt.Rows.Count != 0)//已有记录,则显示出来
        {
            object []item = dt.Rows[0].ItemArray;
            double ratio = 0.035277777777777777777777777777778;//将word中的值转换成CM
           
            this.tbButtomMargin.Text = Math.Round(Convert.ToDouble(item[2]) * ratio, 2).ToString();
            this.tbLeftMargin.Text = Math.Round(Convert.ToDouble(item[3]) * ratio, 2).ToString();
            this.tbRightMargin.Text = Math.Round( Convert.ToDouble(item[4]) *ratio,2).ToString();
            this.tbGutter.Text = Math.Round(Convert.ToDouble(item[5]) * ratio, 2).ToString();
            Utilities.SetSelectDropDownListByValueMember(ddlGutterPos, item[6].ToString());
            Utilities.SetSelectDropDownListByValueMember(ddlPageSize, item[7].ToString());
            this.tbPageWidth.Text = Math.Round(Convert.ToDouble(item[8]) * ratio, 2).ToString();
            this.tbPageHeiht.Text = Math.Round(Convert.ToDouble(item[9]) * ratio, 2).ToString();
            this.tbPageHeader.Text = Math.Round(Convert.ToDouble(item[10]) * ratio, 2).ToString();
            this.tbPageFooter.Text = Math.Round(Convert.ToDouble(item[11]) * ratio, 2).ToString();
            this.tbColnum.Text =item[12].ToString();
            Utilities.SetSelectDropDownListByValueMember(ddlVerticalAlignment,item[13].ToString());
        }
       
    }
    #endregion

    private void LoadParagraphStyleByNameLocal(string strNameLocal)
    {
        DataTable dt = Global.GetFieldsFromTablesByCondiction("*", "ParagraphStyle", "NameLocal like '" + strNameLocal + "'");
        if (dt.Rows.Count != 0)//已有段落记录,则显示出来
        {
            object[] item = dt.Rows[0].ItemArray;
            Utilities.SetSelectDropDownListByValueMember(ddlFontFamily,item[2].ToString());
            Utilities.SetSelectDropDownListByValueMember(ddlFontSize, item[3].ToString());
            this.cbBold.Checked = (bool)item[4];
            this.cbItalic.Checked = (bool)item[5];
            Utilities.SetSelectDropDownListByValueMember(ddlLineSpacingRule, item[6].ToString());
            switch (item[6].ToString())//为多倍,单倍,1.5倍行距时,设置值里为空,只有为非三者之一时,才计算行距值
            {
                case "wdLineSpace1pt5":
                case "wdLineSpaceDouble":
                case "wdLineSpaceSingle":
                    this.tbLineSpacing.Text = "0";
                    break;

                case "wdLineSpaceAtLeast":
                case "wdLineSpaceExactly":
                case "wdLineSpaceMultiple":
                    this.tbLineSpacing.Text = (double.Parse(item[7].ToString()) / 12.0).ToString();
                    break;
            }

            if (item[8].ToString() == "0")//为0行,则单位为磅 lineunitafter=0,则单位为磅
            {
                if (item[10].ToString() == "0")
                    this.tbSpaceAfter.Text = "0";
                else
                    this.tbSpaceAfter.Text = item[10].ToString() + "磅";
            }
            else //单位为行
            {

                tbSpaceAfter.Text = item[8].ToString();
            }

            if (item[9].ToString() == "0")//为0行,则单位为磅
            {
                if (item[11].ToString() == "0")
                    this.tbSpaceBefore.Text = "0";
                else
                    this.tbSpaceBefore.Text = item[11].ToString() + "磅";
            }
            else //单位为行
            {

                tbSpaceBefore.Text = item[9].ToString();
            }

            Utilities.SetSelectDropDownListByValueMember(ddlAlignment,item[12].ToString());
            tbCharacterUnitFirstLineIndent.Text = item[17].ToString();
            tbLeftIndent.Text = item[15].ToString();
            tbRightIndent.Text = item[16].ToString();
        }
    }
    protected void ddlNameLocal_SelectedIndexChanged(object sender, EventArgs e)
    {
        //大纲级别更改时,显示不同的大纲的设置
        LoadParagraphStyleByNameLocal(ddlNameLocal.SelectedValue);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -