当前位置: 首页>>代码示例>>C#>>正文


C# Common.ReadExcelContents方法代码示例

本文整理汇总了C#中Common.ReadExcelContents方法的典型用法代码示例。如果您正苦于以下问题:C# Common.ReadExcelContents方法的具体用法?C# Common.ReadExcelContents怎么用?C# Common.ReadExcelContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Common的用法示例。


在下文中一共展示了Common.ReadExcelContents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnReadExcel_Click

    protected void btnReadExcel_Click(object sender, EventArgs e)
    {
        try
        {
            Visible(false);
            Common cm = new Common();
            InitBUS();
            table = new DataTable();
            long countEmail = 0;
            string excelContent = "application/vnd.ms-excel";
            string excelContent2010 = "application/openxmlformats-officedocument-spreadsheetml.sheet";
            if (fileExcel.HasFile)
            {

                if (fileExcel.PostedFile.ContentType != excelContent && fileExcel.PostedFile.ContentType != excelContent2010)
                {
                    Visible(false);
                    pnError.Visible = true;
                    lblError.Text = "Vui lòng chọn file Excel";
                }
                else
                {
                    if (getUserLogin().DepartmentId == 2)
                    {
                        table = ctBUS.GetClientId(getUserLogin().UserId);
                    }
                    else
                    {
                        table = ctBUS.GetClientIdSub(getUserLogin().UserId);
                    }

                    if (table.Rows.Count > 0)
                    {
                        int clienID = int.Parse(table.Rows[0]["clientId"].ToString());
                        DataTable dtCountEmail = ctBUS.GetCountEmail(clienID);
                        if (dtCountEmail.Rows[0]["isUnLimit"] + "" != "" && Convert.ToBoolean(dtCountEmail.Rows[0]["isUnLimit"])) countEmail = 1000000000000000000;
                        else countEmail = int.Parse(dtCountEmail.Rows[0]["under"].ToString());
                    }

                    fileName = "~/database/" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + fileExcel.FileName;
                    string path = string.Concat(Server.MapPath(fileName));
                    fileExcel.SaveAs(path);
                    table = cm.ReadExcelContents(path);

                    if (table.Rows.Count < countEmail)
                    {
                       // string message = checkCreateCustomer(table.Rows.Count);
                       // if (message == "")
                      //  {
                            this.dtlCustomer.DataSource = table;
                            this.dtlCustomer.DataBind();
                            LoadMailGroupLists();
                       // }
                      //  else
                      //  {
                     //       Visible(false);
                      //      pnError.Visible = true;
                       //     lblError.Text = message;
                      //  }
                    }
                    else
                    {

                        Visible(false);
                        pnError.Visible = true;
                        lblError.Text = "Vượt quá hạng ngạch tạo khách hàng!";

                    }

                }

            }
            else
            {
                Visible(false);
                pnError.Visible = true;
                lblError.Text = "Vui lòng chọn file";
            }
        }
        catch (Exception ex)
        {

            Visible(false);
            pnError.Visible = true;
            lblError.Text = "Vui lòng kiểm tra lại định dạng file, hoặc file của bạn đang được sử dụng <br/>" + ex.ToString();
            logs.Error(userLogin.Username + "-Client - btnReadExcel_Click", ex);
        }
    }
开发者ID:phonglam29305,项目名称:FAMail,代码行数:88,代码来源:AddCustomer.aspx.cs


注:本文中的Common.ReadExcelContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。