Example #1
0
        public ActionResult ExImport(HttpPostedFileBase file)
        {
            //month1 导入数据表
            var    fileName = file.FileName;
            var    filePath = Server.MapPath(string.Format("~/{0}", "FileExecel"));
            string path     = Path.Combine(filePath, fileName);

            file.SaveAs(path);

            DataTable excelTable = new DataTable();

            excelTable = imExpro.GetExcelDataTable(path);

            DataTable dtable = new DataTable();

            dtable.Columns.Add("billdate");
            dtable.Columns.Add("duedate");
            dtable.Columns.Add("rate");
            dtable.Columns.Add("remarks1");
            dtable.Columns.Add("remarks2");



            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                DataRow dr  = excelTable.Rows[i];
                DataRow dr_ = dtable.NewRow();
                dr_["bildate"]  = dr["bildate"];
                dr_["duedate"]  = dr["Duedate"];
                dr_["rate"]     = dr["Rate"];
                dr_["remarks1"] = dr["Remarks1"];
                dr_["remarks2"] = dr["Remarks2"];

                dtable.Rows.Add(dr_);
            }

            string constr = System.Configuration.ConfigurationManager.AppSettings["EFeesEntities"];

            using (TransactionScope tran = new TransactionScope())
            {
                string sql = "delete  from month1";//导入 新的mb1
                SqlHelp.ExecuteNonQuery(constr, sql);
                DataTableSql.SqlBulkCopyByDatatable(constr, "month1", dtable);

                tran.Complete();
            }
            return(Content(fileName.ToString()));
        }
Example #2
0
        public ActionResult ExImport(HttpPostedFileBase file)
        {
            var    fileName = file.FileName;
            var    filePath = Server.MapPath(string.Format("~/{0}", "FileExecel"));
            string path     = Path.Combine(filePath, fileName);

            file.SaveAs(path);

            DataTable excelTable = new DataTable();

            excelTable = imExpro.GetExcelDataTable(path);

            DataTable dtable = new DataTable();

            dtable.Columns.Add("account");
            dtable.Columns.Add("billno");
            dtable.Columns.Add("prev");
            dtable.Columns.Add("pres");
            dtable.Columns.Add("unit");
            dtable.Columns.Add("type");
            dtable.Columns.Add("bf");
            dtable.Columns.Add("odd");
            dtable.Columns.Add("chg");
            dtable.Columns.Add("misc");
            dtable.Columns.Add("bill");
            dtable.Columns.Add("auto");
            dtable.Columns.Add("descs");
            dtable.Columns.Add("name");
            dtable.Columns.Add("address1");
            dtable.Columns.Add("address2");
            dtable.Columns.Add("address3");
            dtable.Columns.Add("date");


            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                DataRow dr  = excelTable.Rows[i];
                DataRow dr_ = dtable.NewRow();
                dr_["account"]  = dr["account"];
                dr_["billno"]   = dr["billno"];
                dr_["prev"]     = dr["prev"];
                dr_["pres"]     = dr["pres"];
                dr_["unit"]     = dr["unit"];
                dr_["type"]     = dr["type"];
                dr_["bf"]       = dr["bf"];
                dr_["odd"]      = dr["odd"];
                dr_["chg"]      = dr["chg"];
                dr_["misc"]     = dr["misc"];
                dr_["bill"]     = dr["bill"];
                dr_["auto"]     = dr["auto"];
                dr_["descs"]    = dr["descs"];
                dr_["name"]     = dr["name"];
                dr_["address1"] = dr["address1"];
                dr_["address2"] = dr["address2"];
                dr_["address3"] = dr["address3"];
                dr_["date"]     = dr["date"];
                dtable.Rows.Add(dr_);
            }

            string constr = System.Configuration.ConfigurationManager.AppSettings["EFeesEntities"];

            using (TransactionScope tran = new TransactionScope())
            {
                string sql = "delete  from m_bills1";//导入 新的mb1
                SqlHelp.ExecuteNonQuery(constr, sql);
                DataTableSql.SqlBulkCopyByDatatable(constr, "m_bills1", dtable);

                tran.Complete();
            }
            return(Content(fileName.ToString()));
        }
        public ActionResult importExDetail(HttpPostedFileBase file)
        {
            var    fileName = file.FileName;
            var    filePath = Server.MapPath(string.Format("~/{0}", "FileExecel"));
            string path     = Path.Combine(filePath, fileName);

            file.SaveAs(path);

            DataTable excelTable = new DataTable();

            excelTable = imExpro.GetExcelDataTable(path);

            DataTable dtable = new DataTable();

            dtable.Columns.Add("account");
            dtable.Columns.Add("billno");
            dtable.Columns.Add("actcode1");
            dtable.Columns.Add("chargeamt1");
            dtable.Columns.Add("actcode2");
            dtable.Columns.Add("chargeamt2");
            dtable.Columns.Add("actcode3");
            dtable.Columns.Add("chargeamt3");
            dtable.Columns.Add("actcode4");
            dtable.Columns.Add("chargeamt4");
            dtable.Columns.Add("actcode5");
            dtable.Columns.Add("chargeamt5");
            dtable.Columns.Add("actcode6");
            dtable.Columns.Add("chargeamt6");
            dtable.Columns.Add("actcode7");
            dtable.Columns.Add("chargeamt7");
            dtable.Columns.Add("actcode8");
            dtable.Columns.Add("chargeamt8");
            dtable.Columns.Add("actcode9");
            dtable.Columns.Add("chargeamt9");


            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                DataRow dr  = excelTable.Rows[i];
                DataRow dr_ = dtable.NewRow();
                dr_["account"]    = dr["account"];
                dr_["billno"]     = dr["billno"];
                dr_["actcode1"]   = dr["actcode1"];
                dr_["chargeamt1"] = dr["chargeamt1"];
                dr_["actcode2"]   = dr["actcode2"];
                dr_["chargeamt2"] = dr["chargeamt2"];
                dr_["actcode3"]   = dr["actcode3"];
                dr_["chargeamt3"] = dr["chargeamt3"];
                dr_["actcode4"]   = dr["actcode4"];
                dr_["chargeamt4"] = dr["chargeamt4"];
                dr_["actcode5"]   = dr["actcode5"];
                dr_["chargeamt5"] = dr["chargeamt5"];
                dr_["actcode6"]   = dr["actcode6"];
                dr_["chargeamt6"] = dr["chargeamt6"];
                dr_["actcode7"]   = dr["actcode7"];
                dr_["chargeamt7"] = dr["chargeamt7"];
                dr_["actcode8"]   = dr["actcode8"];
                dr_["chargeamt8"] = dr["chargeamt8"];
                dr_["actcode9"]   = dr["actcode9"];
                dr_["chargeamt9"] = dr["chargeamt9"];
                dtable.Rows.Add(dr_);
            }

            string constr = System.Configuration.ConfigurationManager.AppSettings["EFeesEntities"];

            using (TransactionScope tran = new TransactionScope())
            {
                string sql = "delete  from m_detail1";//导入 新的mdetail1
                SqlHelp.ExecuteNonQuery(constr, sql);
                DataTableSql.SqlBulkCopyByDatatable(constr, "m_detail1", dtable);

                tran.Complete();
            }
            return(Content(fileName.ToString()));
        }