app.config中的配置不太熟,请各位大哥大姐多指教.

解决方案 »

  1.   

    另外还问个问题,代码如下:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.Odbc;
    using System.Data.SqlClient;
    using System.IO;
    using System.Data.OleDb;namespace hkmessages
    {
        public partial class formMonthHk : Form
        {
            //连接数据源 这里直接连接oledb
           // string ConnStr = "Provider=Sybase.ASEOleDbProvider.2;Data Source=housedbSZ;User ID=sa; providerName='System.Data.OleDb'";
           
            public formMonthHk()
            {
                InitializeComponent();        }
            private void formMonthHk_Load(object sender, EventArgs e)
            {
             
            }
            private void btnOut_oledb_Click(object sender, EventArgs e)
            {
                int iyear = Convert.ToDateTime(txtYearMonth.Text.Trim()).Year;
                int imonth = Convert.ToDateTime(txtYearMonth.Text.Trim()).Month;
                string strWrite;
                string hkCause = "";//划款原因
                string ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
                //建立连接,这里也web.config差不多,要添加system.configuration.dll引用
                OleDbConnection mycn = new OleDbConnection(ConnStr);
                string strSQL = "select hkmx.i_year,hkmx.i_month,hkmx.s_dkgrzh,hkmx.i_hk_flag,hkmx.s_grxm,hkmx.dc_je,hkmx.dc_po_je,dkxx.s_grzh,dkxx.s_mobile_phone";
                strSQL += " from yxwt_hkmx hkmx,nd_grdkxx_ma dkxx where hkmx.s_dkgrzh=dkxx.s_grzh and hkmx.i_year=" + iyear.ToString() + " and hkmx.i_month=" + imonth.ToString();
                try
                {
                    //string txtPath = "E:\\" + iyear + txtYearMonth.Text.Trim().Substring(5, 2) + ".txt";
                   // lblPath.Text=txtPath;   //这里获取.txt文件路径不知为什么在界面的label.text中不显示 ,所以下面还是指定了固定路径
                    StreamWriter hkInfo = new StreamWriter(lblPath.Text, false, Encoding.Default);
                    mycn.Open();
                    OleDbCommand mycmd = new OleDbCommand(strSQL, mycn);
                    OleDbDataReader myreader = mycmd.ExecuteReader();                while(myreader.Read())
                    {
                        short hk_flag = Convert.ToInt16(myreader["i_hk_flag"]);
                        string grxm = myreader["s_grxm"].ToString();
                        //string poxm = myreader["s_po_grxm"].ToString();//配偶姓名
                        decimal dc_je = Convert.ToDecimal(myreader["dc_je"]);
                        decimal dc_po_je = Convert.ToDecimal(myreader["dc_po_je"]);
                        string handtelephone =myreader["s_mobile_phone"].ToString();                    decimal moneys = dc_je + dc_po_je;//夫妻双方的总金额                    if (moneys>0 && dc_po_je>0)
                        {
                            hkCause = "尊敬的" + grxm.Trim().Replace(" ", "") + "," + imonth + "月份从您的住房公积金账户内划转" + dc_je + "元,从您爱人的账户内划转" + dc_po_je + "元,以上资金已转入您的还贷存折账户.";
                        }                    if(moneys>0 && dc_po_je==0)
                        {
                            hkCause = "尊敬的" + grxm.Trim().Replace(" ", "") + "," + imonth + "月份从您的住房公积金账户内划转" + dc_je + "元,资金已转入您的还贷存折账户.";
                        }                    if(moneys==0 && hk_flag != 12 && hk_flag != 11)
                        {
                            hkCause ="尊敬的" + grxm.Trim().Replace(" ", "") +",由于住房公积金账户内余额不足,"+imonth+"月份按月划转失败.请尽快向还贷存折账户内补足资金,以免造成逾期.";
                        }                    if(hk_flag==11)
                        {                        hkCause = "尊敬的" + grxm.Trim().Replace(" ", "") +",由于您上月未按时偿还住房公积金贷款,"+imonth+"月份按月划转失败.";
                        }
            
                        if (handtelephone != "" && handtelephone.Length == 11)
                        {//这里判断是否为手机号,如果为手机号码才执行相应操作
                            strWrite = handtelephone + " " + hkCause;
                            hkInfo.WriteLine(strWrite);
                        }
                    
                    }                lblInfo.Text = "成功导出目标文件!";                if (!myreader.Read())
                    {//如果读入为空,就提示信息不存在
                        hkInfo.Close();//关闭数据流
                        mycn.Close();//关
                        lblInfo.Text = lblMsg.Text = "对不起," + iyear + "年" + imonth + "月的信息不存在!";
                    }
                    
                    hkInfo.Close();//关闭数据流
                    mycn.Close();//关闭连接
                  
                }
                catch (Exception ex)
                {
                    mycn.Close();
                    lblInfo.Text = "信息导出失败!";
                }        }
           
           //结尾    }
    }
    //string txtPath = "E:\\" + iyear + txtYearMonth.Text.Trim().Substring(5, 2) + ".txt";
    // lblPath.Text=txtPath; 
    在lblPath.Text中不能正常显示动态生成的路径名,这是什么原因,我单步调试都可以正常显,但在界面上不能显示出来