Exemple #1
0
        //报警删除
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string key1 = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
            string key2 = GridView1.DataKeys[e.RowIndex].Values[1].ToString();

            int flag = DataOperate.deleteInvoiceInfo(key1, key2);

            if (flag > 0)
            {
                string invoiceType = this.DropDownList1.SelectedValue.ToString();
                //起始日期
                string startDate = this.startDate.Text;
                //结束日期
                string endDate = this.endDate.Text;
                //string endDate = this.DropDownList_DepotType.SelectedValue;
                //填充数据源
                //GridView1.DataSource = CheckStatBll.getCheckStatByCondition(materialType, depotId, depotType, goodsName);
                string  operatorID = Request.LogonUserIdentity.Name;
                DataSet ds         = DataOperate.exportInvoiceInfo(invoiceType, startDate, endDate, operatorID);
                DataSet ds1        = DataOperate.queryInvoiceInfo(invoiceType, startDate, endDate, operatorID);
                GridView1.DataSource   = ds1.Tables[0];
                GridView1.DataKeyNames = new string[] { "InvoiceCode", "InvoiceNumber" };//主键
                GridView1.DataBind();
                GridView2.DataSource = ds.Tables[1];
                GridView2.DataBind();
                Response.Write("<script language=javascript>alert('删除发票代码:" + key1 + ",号码:" + key2 + "记录成功!');</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('删除发票记录失败!');</script>");
            }
        }
Exemple #2
0
        protected void export_Click(object sender, EventArgs e)
        {
            string style = @"<style type=""text/css"">td{mso-number-format:'\@';text-align:center;}</style>";

            //从页面取到查询条件
            //发票类型代码:00所有/01专票/04普票
            string invoiceType = this.DropDownList1.SelectedValue.ToString();
            //起始日期
            string startDate = this.startDate.Text;
            //结束日期
            string endDate = this.endDate.Text;
            //填充数据源
            string operatorID = Request.LogonUserIdentity.Name;

            if (invoiceType != "" && startDate != "" && endDate != "" && operatorID != "")
            {
                DataSet ds = DataOperate.exportInvoiceInfo(invoiceType, startDate, endDate, operatorID);
                if (!(ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
                {
                    Response.Write("<script language=javascript>alert('该时间段内没有该类型发票!');</script>");
                }
                else
                {
                    Response.ClearContent();
                    //Response.Buffer = true;
                    //Response.Charset = "gb2312";
                    //Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    Response.Charset         = "UTF-8";
                    Response.ContentEncoding = System.Text.Encoding.UTF8;
                    Response.AddHeader("content-disposition", "attachment; filename=export.xls");
                    Response.ContentType = "application/ms-excel";
                    StringWriter   sw   = new StringWriter();
                    HtmlTextWriter htw  = new HtmlTextWriter(sw);
                    StringWriter   sw2  = new StringWriter();
                    HtmlTextWriter htw2 = new HtmlTextWriter(sw2);
                    //导出前将GridView排序和分页都关闭
                    GridView1.AllowPaging  = false;
                    GridView1.AllowSorting = false;
                    GridView1.DataSource   = ds.Tables[0];
                    GridView2.DataSource   = ds.Tables[1];
                    //绑定数据源
                    GridView1.DataBind();
                    GridView2.DataBind();
                    // 清除GridView1中的所有控件,以便导出Excel
                    ClearControls(GridView1);
                    GridView1.RenderControl(htw);
                    GridView2.RenderControl(htw2);
                    //Style为导出Excel时的格式(有个五六种吧,去网上查一下)
                    Response.Write(style);
                    Response.Write(sw.ToString());
                    Response.Write(sw2.ToString());
                    Response.Flush();
                    Response.End();
                    //导出前将GridView分页打开
                    GridView1.AllowPaging  = true;
                    GridView1.AllowSorting = false;
                    //重新绑定数据源
                    //DataSet ds = DataOperate.queryInvoiceInfo("61106", "20170101", "20171231");
                    GridView1.DataSource   = ds.Tables[0];
                    GridView1.DataKeyNames = new string[] { "InvoiceCode", "InvoiceNumber" };//主键
                    GridView1.DataBind();
                }
            }
            else
            {
                Response.Write("<script language=javascript>alert('请完善查询起止日期!');</script>");
            }
        }