Esempio n. 1
0
 /// <summary>                                                          
 /// 加桩Csv文件查询结果转换成泛型集合                                         
 /// </summary>                                                                            
 /// <param name="filePath">文件路径</param>                         
 /// <returns>以实体类为元素的泛型集合</returns>
 public List<AdditionalStake> ImportAdditionalStakeList(string filePath)
 {
     List<AdditionalStake> adds = new List<AdditionalStake>();
     StreamReader fileReader = new StreamReader(filePath, Encoding.Default);
     try
     {
         //列之间的分隔符
         char cv = ',';
         while (fileReader.EndOfStream == false)
         {
             AdditionalStake t = new AdditionalStake();
             string line = fileReader.ReadLine();
             string[] y = line.Split(cv);
             t.Stake = y[0].Trim().ToString();
             t.Description= y[1].Trim().ToString();
             adds.Add(t);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         fileReader.Close();
         fileReader.Dispose();
     }
     return adds;
 }
    //public override void VerifyRenderingInServerForm(Control control)
    //{
    //    //base.VerifyRenderingInServerForm(control);
    //}
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ads = new AdditionalStake("Data Source=Localhost;database=RoadCenter;User ID=admin;Password=admin123");

            //读取传参
            Route.Text = "线路:" + Request.Cookies["RouteID"].Value;// Session["RouteID"].ToString();
                                                                  //调用Databind方法
            Databind();
            AdditionalStake.Columns[5].Visible = true;

        }
        if (IsPostBack)
        {
            ads = new AdditionalStake("Data Source=Localhost;database=RoadCenter;User ID=admin;Password=admin123");
        }

        if (this.AdditionalStake.SelectedIndex > -1)
        {
            // 调用GridView的UpdateRow方法
            this.AdditionalStake.UpdateRow(this.AdditionalStake.SelectedIndex, false);
        }
    }
 protected void import_Click(object sender, EventArgs e)
 {
     if (file.HasFile == false)// 判断fileupload是否有指定文件
     {
         Response.Write("<script>alert('请您选择Excel文件')</script>");
         return;//当无文件时,返回
     }
     string filename = file.PostedFile.FileName;
     List<AdditionalStake> ads = new List<AdditionalStake>();
     CsvFileImport cfi = new CsvFileImport();
     ads = cfi.ImportAdditionalStakeList(filename);
 }
 /// <summary>
 /// 加载加桩
 /// </summary>
 /// <param name="RouteID"></param>
 /// <returns></returns>
 public List<AdditionalStake> Load(int RouteID)
 {
     List<AdditionalStake> list = new List<AdditionalStake>();
     if (DbConnection == null) return null;
     string sql = @"select * from RDC_AdditionalStake where RouteID='" + RouteID + "'";
     DataSet ds= DbConnection.GetDataSet(sql);
     foreach (DataRow r in ds.Tables[0].Rows)
     {
         AdditionalStake add = new AdditionalStake();
         add.AddStakeID= r["AddStakeID"] == DBNull.Value ? 0 : Convert.ToInt32(r["AddStakeID"]);
         add.RouteID= r["RouteID"] == DBNull.Value ? 0 : Convert.ToInt32(r["RouteID"]);
         add.Stake = r["Stake"].ToString();
         add.Description = r["Description"].ToString();
         list.Add(add);
     }
     return list;
 }