private void CreatNewApp(string mFile) { //获取当前Tab索引 int mType = Tab.SelectedIndex; //获取当前应用程序列表 mAppList = getAppList(mType); //获得XmlDB数据库 XmlDB mDB = XmlDBFactory.LoadXmlDB(mFileName); SmartApp mApp = new SmartApp(mFile, mNames[mType].ToString()); mDB.Insert(mApp); mDB.Commit(); //构建界面 SmartAppControl mControl = mApp.BuilderUI(new RoutedEventHandler(App_Click), new RoutedEventHandler(App_Click)); if (mAppList.Count < 4) { mControl.SetValue(Grid.RowProperty, 0); mControl.SetValue(Grid.ColumnProperty, mAppList.Count); } else { mControl.SetValue(Grid.RowProperty, (mAppList.Count) / 4); mControl.SetValue(Grid.ColumnProperty, (mAppList.Count) % 4); } Grid mGrid = getGrid(mNames[mType]); //添加App到桌面 mGrid.Children.Add(mControl); //修改词典 mAppList = getAppList(mType); mAppList.Add(mApp); }
/// <summary> /// 初始化应用程序 /// </summary> private void InitAPP() { //创建程序数据目录 if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\SmartHome\\Data")) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\SmartHome\\Data"); } //创建数据文件路径 mFileName = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\SmartHome\\Data\\Data.Xml"; if (!File.Exists(mFileName)) { //创建XmlDB XmlDB mDB = XmlDBFactory.CreatXmlDB("SmartHome", mFileName, 1); //插入预设的应用程序 mDB.Insert(new SmartApp("记事本", "C:\\Windows\\system32\\notepad.exe", "工具")); mDB.Insert(new SmartApp("截图工具", "C:\\Windows\\system32\\SnippingTool.exe", "工具")); mDB.Insert(new SmartApp("画图", "C:\\Windows\\system32\\mspaint.exe", "工具")); mDB.Insert(new SmartApp("IE", "C:\\Program Files\\Internet Explorer\\iexplore.exe", "工具")); mDB.Commit(); } ReadApps(); }
/// <summary> /// 保存单个设置 /// </summary> /// <param name="i"></param> public void Save(FontDB i) { if (!String.IsNullOrEmpty(i.PrimaryGuid)) { i.UpdateTime = DateTime.Now; mDB.Update(new FontDB() { PrimaryGuid = i.PrimaryGuid }, i); } else { i.PrimaryGuid = Guid.NewGuid().ToString("N"); i.UpdateTime = i.CreateTime = DateTime.Now; mDB.Insert(i); } }
/// <summary> /// 初始化天气 /// </summary> private void InitWeather() { //如果网络已连接,则获取最新的天气,否则读取本地天气 if (WebState.isConneted()) { //获取天气 WeatherStructure mWeather = WebWeather.getWeatherByCode(WebWeather.getCodeByIP()); SetWeather(mWeather); //更新本地数据 File.Delete(Config + "\\Weather.xml"); XmlDB mDB = XmlDBFactory.CreatXmlDB("Weather", Config + "\\Weather.xml", 1); mDB.Insert(mWeather); mDB.Commit(); } else { XmlDB mDB = XmlDBFactory.LoadXmlDB(Config + "\\Weather.xml"); List <object> mObjects = mDB.ReadByObject(new WeatherStructure()); WeatherStructure mWeather = (WeatherStructure)mObjects[0]; SetWeather(mWeather); } }