protected void btnLoadOut_Click(object sender, EventArgs e)
    {
        ChangeTrackingList <EntitySearcher>  changeTrackingList = ViewState["sql"] as ChangeTrackingList <EntitySearcher>;
        List <FineOffice.Modules.CRM_Trader> list = traderBll.GetList(changeTrackingList);

        FineOffice.Web.WebExcelHelper       excelHelper = new FineOffice.Web.WebExcelHelper();
        FineOffice.Common.Excel.ExcelHelper toExcel     = new FineOffice.Common.Excel.ExcelHelper();
        string             serverPath = Server.MapPath("~/Config/Template/CRM_Trader.xml");
        List <ExcelHeader> headerList = toExcel.GetHeaderList(serverPath);

        toExcel.ApplicationName = excelHelper.ApplicationName;
        toExcel.Author          = excelHelper.Author;
        toExcel.Comments        = excelHelper.Comments;
        System.IO.MemoryStream ms = toExcel.Export <FineOffice.Modules.CRM_Trader>(list, traderGrid.Title, headerList);
        byte[] output             = ms.ToArray();

        FineOffice.Web.FileTypeHelper typeHelper = new FineOffice.Web.FileTypeHelper();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + typeHelper.ToHexString(string.Format("{0}{1:yyyyMMdd}", traderGrid.Title, DateTime.Now) + ".xls"));
        Response.AddHeader("Content-Length", output.Length.ToString());
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
        Response.OutputStream.Write(output, 0, output.Length);

        Response.Flush();
        Response.End();
    }
Example #2
0
    protected void btnLoad_Click(object sender, EventArgs e)
    {
        try
        {
            if (uploadFile.HasFile)
            {
                HttpPostedFile excel      = uploadFile.PostedFile;
                Stream         fileStream = excel.InputStream;

                FineOffice.Web.WebExcelHelper excelHelper = new FineOffice.Web.WebExcelHelper();

                FineOffice.Common.Excel.ExcelHelper toExcel = new FineOffice.Common.Excel.ExcelHelper();
                string             serverPath = Server.MapPath("~/Config/Template/CNS_CensusMember.xml");
                List <ExcelHeader> headerList = toExcel.GetHeaderList(serverPath);

                List <FineOffice.Modules.CNS_CensusMember> list = toExcel.Import <FineOffice.Modules.CNS_CensusMember>(fileStream, 0, 0, headerList);
                fileStream.Close();
                uploadFile.Reset();

                gridMember.DataSource = list;
                gridMember.DataBind();
            }
        }
        catch (Exception ex)
        {
            Alert.Show(ex.Message);
        }
    }
Example #3
0
    protected void btnTemplates_Click(object sender, EventArgs e)
    {
        FineOffice.Web.WebExcelHelper       excelHelper = new FineOffice.Web.WebExcelHelper();
        FineOffice.Common.Excel.ExcelHelper toExcel     = new FineOffice.Common.Excel.ExcelHelper();
        string             serverPath = Server.MapPath("~/Config/Template/CNS_CensusMember.xml");
        List <ExcelHeader> headerList = toExcel.GetHeaderList(serverPath);

        toExcel.ApplicationName = excelHelper.ApplicationName;
        toExcel.Author          = excelHelper.Author;
        toExcel.Comments        = excelHelper.Comments;
        System.IO.MemoryStream ms = toExcel.Export <FineOffice.Modules.CNS_CensusMember>(new List <FineOffice.Modules.CNS_CensusMember>(), memberGird.Title, headerList);
        byte[] output             = ms.ToArray();

        FineOffice.Web.FileTypeHelper typeHelper = new FineOffice.Web.FileTypeHelper();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + typeHelper.ToHexString(memberGird.Title + ".xls"));
        Response.AddHeader("Content-Length", output.Length.ToString());
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); //设置输出流的字符集
        Response.OutputStream.Write(output, 0, output.Length);                //输出

        Response.Flush();
        Response.End();
    }
Example #4
0
    /// <summary>
    /// 保存导入数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        FineOffice.Common.Excel.ExcelHelper toExcel     = new FineOffice.Common.Excel.ExcelHelper();
        FineOffice.Web.WebExcelHelper       excelHelper = new FineOffice.Web.WebExcelHelper();
        string             serverPath = Server.MapPath("~/Config/Template/CNS_CensusMember.xml");
        List <ExcelHeader> headerList = toExcel.GetHeaderList(serverPath);

        try
        {
            foreach (GridRow row in gridMember.Rows)
            {
                gridMember.SelectedRowIndex = row.RowIndex;
                Dictionary <string, object> valueMap = new Dictionary <string, object>();
                foreach (GridColumn column in gridMember.Columns)
                {
                    FineUI.BoundField field = column as FineUI.BoundField;
                    string            value = row.Values[column.ColumnIndex].ToString();
                    if (field != null)
                    {
                        valueMap.Add(field.DataField, value);
                    }
                }
                FineOffice.Modules.CNS_CensusMember   model    = toExcel.Create <FineOffice.Modules.CNS_CensusMember>(headerList, valueMap);
                FineOffice.Modules.CNS_CensusRegister register = registerBll.GetModel(m => m.RegisterNO == model.RegisterNO);
                if (register == null)
                {
                    register             = new FineOffice.Modules.CNS_CensusRegister();
                    register.RegisterNO  = model.RegisterNO;
                    register.HouseHolder = model.HouseHolder;
                    FineOffice.Modules.CNS_CensusType type = typeBll.GetModel(t => t.CensusTypeName == model.CensusTypeName);
                    if (type == null)
                    {
                        type = new FineOffice.Modules.CNS_CensusType();
                        type.CensusTypeName = model.CensusTypeName;
                        type = typeBll.Add(type);
                    }
                    register.CensusTypeID = type.ID;
                    registerBll.Add(register);
                }
                if (model.Gender == "男")
                {
                    model.Sex = 1;
                }
                else
                {
                    model.Sex = 0;
                }

                FineOffice.Modules.CNS_PoliticalAffiliation political = politicalBll.GetModel(m => m.Political == model.Political);
                if (political == null)
                {
                    political           = new FineOffice.Modules.CNS_PoliticalAffiliation();
                    political.Political = model.Political;
                    political           = politicalBll.Add(political);
                }
                model.PoliticalID = political.ID;

                FineOffice.Modules.AM_Kind kind = kindBll.GetModel(m => m.Name == model.Education);
                if (kind != null)
                {
                    model.EducationID = kind.ID;
                }
                memberBll.Add(model);
            }
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference("member_close"));
        }
        catch (Exception ex)
        {
            FineUI.Alert.ShowInParent(ex.Message);
        }
    }