public static string UpdateDataBaseDataSource(DesignerDataBaseDataSource ds)
        {
            string path = Directory.GetCurrentDirectory() + @"\DataSources\DataBase\" + ds.Name + ".bds";

            try
            {
                MemoryStream  Stream = new MemoryStream();
                XmlSerializer xml    = new XmlSerializer(typeof(DesignerDataBaseDataSource));
                //序列化对象
                xml.Serialize(Stream, ds);
                Stream.Position = 0;
                StreamReader sr  = new StreamReader(Stream);
                string       str = sr.ReadToEnd();
                //存到文件

                FileStream   fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sw = new StreamWriter(fs); // 创建写入流
                sw.Write(str);
                sw.Close();
                sr.Dispose();
                Stream.Dispose();

                //注册该数据源
                DataSourceManager.Register(ds.Name, ds.DataSourceType, ds);


                return(path);
            }
            catch (Exception e)
            {
                throw new Exception("增加数据库数据源时出错:" + e.Message);
            }
        }
        /// <summary>
        /// 数据库名下拉框下拉时,远程获取所有数据库名
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DSDBCB_DropDownOpened(object sender, EventArgs e)
        {
            if (this.SelectedItem == null)
            {
                return;
            }
            if (!(this.SelectedItem is DesignerDataBaseDataSource))
            {
                return;
            }
            DesignerDataBaseDataSource ds = SelectedItem as DesignerDataBaseDataSource;

            if (!string.IsNullOrEmpty(ds.Address) && !string.IsNullOrEmpty(ds.UserName) && !string.IsNullOrEmpty(ds.PassWord))
            {
                string constr = string.Format("Server={0};database={1};uid={2};pwd={3}", ds.Address, "master", ds.UserName, ds.PassWord);
                using (SqlExcuter se = new SqlExcuter(DataBaseType.SqlServer, constr))
                {
                    DataTable data = se.ExecuteSelectSql("select name from master..sysdatabases");
                    DSDBCB.Items.Clear();
                    foreach (DataRow r in data.Rows)
                    {
                        string n = r["name"].ToString();
                        DSDBCB.Items.Add(n);
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入完整信息");
            }
        }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            DesignerDataSource ds      = null;
            TabItemEx          tabItem = MainTab.SelectedItem as TabItemEx;

            switch (tabItem.Header.ToString())
            {
            case "数据库":
                ds = new DesignerDataBaseDataSource();
                DataBaseDataSourceList.Add(ds as DesignerDataBaseDataSource);
                break;

            case "本地文件":
                throw new NotImplementedException();
                break;

            case "网络资源":
                throw new NotImplementedException();
                break;

            case "静态文本":
                ds = new DesignerStaticTextDataSource();
                StaticTextDataSourceList.Add(ds as DesignerStaticTextDataSource);
                break;

            default:
                throw new NotImplementedException();
            }
            this.SelectedItem = ds;
        }
 /// <summary>
 /// 使用Indusfo.DAL 返回DataTable
 /// </summary>
 /// <param name="designerDataBaseDataSource"></param>
 /// <returns></returns>
 private static Task <DataTable> ExcuteDataBaseDataSource(DesignerDataBaseDataSource ds)
 {
     return(Task <DataTable> .Run(() =>
     {
         using (SqlExcuter se = new SqlExcuter(DataBaseType.SqlServer, ds.ConnectionString))
         {
             return se.ExecuteSelectSql(ds.SqlString);
         }
     }));
 }
        public static IEnumerable <DesignerDataBaseDataSource> GetDataBaseDataSources()
        {
            List <DesignerDataBaseDataSource> dss = new List <DesignerDataBaseDataSource>();
            string curDirPath = Directory.GetCurrentDirectory() + @"\DataSources\DataBase";

            //若不存在文件夹则先创建
            if (!Directory.Exists(curDirPath))
            {
                Directory.CreateDirectory(curDirPath);
            }
            DirectoryInfo di = new DirectoryInfo(curDirPath);

            FileInfo[] fis = di.GetFiles();
            try
            {
                foreach (FileInfo fi in fis)
                {
                    string ext = fi.Extension.ToLower();
                    if (ext.IndexOf("bds") == -1 && ext.IndexOf("xml") == -1)
                    {
                        continue;
                    }
                    else
                    {
                        string xml = File.ReadAllText(fi.FullName);
                        using (StringReader sr = new StringReader(xml))
                        {
                            XmlSerializer xmldes          = new XmlSerializer(typeof(DesignerDataBaseDataSource));
                            DesignerDataBaseDataSource ds = xmldes.Deserialize(sr) as DesignerDataBaseDataSource;
                            dss.Add(ds);
                        }
                    }
                }
                return(dss);
            }
            catch (Exception e)
            {
                throw new Exception("读取DataSources时出错:" + e.Message);
            }
        }