zoukankan      html  css  js  c++  java
  • 开发订餐管理系统的一些总结

    一:在前台通过js获取DropDownList 控件选中的值

     var dropDownList = document.getElementById("<%=DropDownListID.ClientID %>"); //获取DropDownList控件
    var dropDownListValue = dropDownList.options[dropDownList.selectedIndex].value; //获取选择项的值

    二:最后一行显示的是GridView一列的相加结果

    找到RowDataBound事件,双击注册后,写入如下代码

                if (e.Row.RowIndex >= 0)
    {
    sum += Convert.ToInt32(e.Row.Cells[4].Text);
    }
    else if (e.Row.RowType == DataControlRowType.Footer)
    { //第几列
    e.Row.Cells[3].Text = "合计:";
    e.Row.Cells[4].Text = sum.ToString() + "";
    }

    三:鼠标移到GridView后改变行的背景颜色

    一样是在RowDataBound事件函数里面写如下代码

            protected void GVPersonal_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    //如果是绑定数据行
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    //鼠标经过时,行背景色变
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
    //鼠标移出时,行背景色变
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
    }
    }

    四:后台导出GridView的数据到Excel

    这方法导出的就是你所看到的Gridview数据,连样式都导出来的

            /// <summary>
    /// 导出Excell
    /// </summary>
    /// <param name="FileType"></param>
    /// <param name="FileName"></param>
    private void Export(string fileType, string fileName)
    {
    Response.Clear();
    Response.Charset = "GB2312";
    Response.ContentEncoding = System.Text.Encoding.Default;//如果导出乱码就改这里的编码
    Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8).ToString());
    Response.ContentType = fileType;
    this.EnableViewState = false;
    StringWriter tw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(tw);
    if (CalculateType.SelectedItem.Value == "Person")//有checkbox出错
    GVPersonal.RenderControl(hw);
    else
    GVDept.RenderControl(hw);
    Response.Write(tw.ToString());
    Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    }

    主要是参考GridView 72般绝技


    五:前台js导出GridView

    需要自己拼的

    主要的参考js如下

            function OutExcel()
    {
    var i,j;
    try
    {
    var xls= new ActiveXObject("Excel.Application");
    }
    catch(e)
    {
    alert( "要打印该表,您必须安装Excel电子表格软件,同时浏览器须使用“ActiveX 控件”,您的浏览器须 允许执行控件。 请点击【帮助】了解浏览器设置方法!");
    return "";
    }

    xls.visible =true; //设置excel为可见

    var xlBook = xls.Workbooks.Add;
    var xlsheet = xlBook.Worksheets(1);

    <!--合并-->
    xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).mergecells=true;
    xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).value="发卡记录";
    // xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Interior.ColorIndex=5;//设置底色为蓝色
    // xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Font.ColorIndex=4;//设置字体色
    // xlsheet.Rows(1). Interior .ColorIndex = 5 ;//设置底色为蓝色 设置背景色 Rows(1).Font.ColorIndex=4

    <!--设置行高-->
    xlsheet.Rows(1).RowHeight = 25;

    <!--设置字体 ws.Range(ws.Cells(i0+1,j0), ws.Cells(i0+1,j1)).Font.Size = 13 -->
    xlsheet.Rows(1).Font.Size=14;

    <!--设置字体 设置选定区的字体 xlsheet.Range(xlsheet.Cells(i0,j0), ws.Cells(i0,j0)).Font.Name = "黑体" -->
    xlsheet.Rows(1).Font.Name="黑体";

    <!--设置列宽 xlsheet.Columns(2)=14;-->
    xlsheet.Columns("A:D").ColumnWidth =18;

    <!--设置显示字符而不是数字-->
    xlsheet.Columns(2).NumberFormatLocal="@";
    xlsheet.Columns(7).NumberFormatLocal="@";

    // 设置单元格内容自动换行 range.WrapText = true ;
    // 设置单元格内容水平对齐方式 range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;//设置单元格内容竖直堆砌方式
    // range.VerticalAlignment=Excel.XlVAlign.xlVAlignCenter
    // range.WrapText = true; xlsheet.Rows(3).WrapText=true 自动换行

    //设置标题栏

    xlsheet.Cells(2,1).Value="卡号";
    xlsheet.Cells(2,2).Value="密码";
    xlsheet.Cells(2,3).Value="计费方式";
    xlsheet.Cells(2,4).Value="有效天数";
    xlsheet.Cells(2,5).Value="金额";
    xlsheet.Cells(2,6).Value="所属服务项目";
    xlsheet.Cells(2,7).Value="发卡时间";

    /*
    var oTable=document.all['fors:data'];
    var rowNum=oTable.rows.length;
    for(i=2;i<=rowNum;i++)
    {
    for (j=1;j<=7;j++)
    {
    //html table类容写到excel
    xlsheet.Cells(i+1,j).Value=oTable.rows(i-1).cells(j-1).innerHTML;
    }
    }
    */

    <!-- xlsheet.Range(xls.Cells(i+4,2),xls.Cells(rowNum,4)).Merge; -->
    // xlsheet.Range(xlsheet.Cells(i, 4), xlsheet.Cells(i-1, 6)).BorderAround , 4
    // for(mn=1,mn<=6;mn++) . xlsheet.Range(xlsheet.Cells(1, mn), xlsheet.Cells(i1, j)).Columns.AutoFit;
    xlsheet.Columns.AutoFit;
    xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(rowNum+1,7)).HorizontalAlignment =-4108;//居中
    xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(1,7)).VerticalAlignment =-4108;
    xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Font.Size=10;

    xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(3).Weight = 2; //设置左边距
    xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(4).Weight = 2;//设置右边距
    xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(1).Weight = 2;//设置顶边距
    xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(2).Weight = 2;//设置底边距

    xls.UserControl = true; //很重要,不能省略,不然会出问题 意思是excel交由用户控制
    xls=null;
    xlBook=null;
    xlsheet=null;
    }

    六:在前台判断CheckBox是否被勾选

    <asp:CheckBox ID="CB_Lunch" runat="server" Text="当天中餐:" onclick="SetDefault()" title="点击选择框订餐默认是一份,可修改多份" />
     function SetDefault() {
    if (document.getElementById("CB_Lunch").checked)
    document.getElementById("TB_Lunch").value = 1;
    }








  • 相关阅读:
    treeview(树加载)
    9.SQL存储过程实例详解
    面向对象之封装
    cookie和session
    自定义web框架
    IO多路复用
    协程
    concurrent.futures模块(进程池/线程池)
    死锁与递归锁及信号量等
    并发编程之多线程
  • 原文地址:https://www.cnblogs.com/jiekk/p/2302680.html
Copyright © 2011-2022 走看看