/// <summary> /// 保存多个设置并提交 /// </summary> /// <param name="Settings"></param> public void Save(List <FontDB> Settings) { foreach (FontDB s in Settings) { Save(s); } mDB.Commit(); }
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 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); } }
/// <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> private void App_Click(object sender, RoutedEventArgs e) { if (!isEditable) { //获取当前活动Tab索引 int mType = Tab.SelectedIndex; //获取Button Button mBtn = (Button)sender; //获取当前父控件 StackPanel mPanel = (StackPanel)mBtn.Parent; Grid mGrid = (Grid)mPanel.Parent; SmartAppControl mControl = (SmartAppControl)mGrid.Parent; //获取父控件在Grid中的行数和列数 int mRow = (int)mControl.GetValue(Grid.RowProperty); int mCol = (int)mControl.GetValue(Grid.ColumnProperty); //计算元素索引 int mIndex = 4 * mRow + mCol; //获取指定类型的应用程序列表 mAppList = getAppList(mType); //获取应用程序 SmartApp mApp = mAppList[mIndex]; if (!File.Exists(mApp.AppPath)) { if (MessageBox.Show("文件不存在或者应用程序无法打开!是否删除该应用?", "删除应用", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { //从列表中移除mApp mAppList.RemoveAt(mIndex); //修改数据文件 XmlDB mDB = XmlDBFactory.LoadXmlDB(mFileName); mDB.Delete(new SmartApp(mApp.AppName, mApp.AppPath, mNames[mType])); mDB.Commit(); //从桌面中移除该应用程序 getGrid(mNames[mType]).Children.Remove(mControl); //移除全部应用程序 getGrid(mNames[mType]).Children.Clear(); //重新加载应用程序 CreateAppForGrid(getGrid(mNames[mType]), mAppList); } } else { //启动应用程序 mApp.Start(); } } else { //获取当前活动Tab索引 int mType = Tab.SelectedIndex; //获取Button Button mBtn = (Button)sender; //获取当前父控件 Grid mGrid = (Grid)mBtn.Parent; SmartAppControl mControl = (SmartAppControl)mGrid.Parent; //获取父控件在Grid中的行数和列数 int mRow = (int)mControl.GetValue(Grid.RowProperty); int mCol = (int)mControl.GetValue(Grid.ColumnProperty); //计算元素索引 int mIndex = 4 * mRow + mCol; //获取指定类型的应用程序列表 mAppList = getAppList(mType); //获取应用程序 SmartApp mApp = mAppList[mIndex]; //从列表中移除mApp mAppList.RemoveAt(mIndex); //修改数据文件 XmlDB mDB = XmlDBFactory.LoadXmlDB(mFileName); mDB.Delete(new SmartApp(mApp.AppName, mApp.AppPath, mNames[mType])); mDB.Commit(); //从桌面中移除该应用程序 getGrid(mNames[mType]).Children.Remove(mControl); //移除全部应用程序 getGrid(mNames[mType]).Children.Clear(); //重新加载应用程序 CreateAppForGrid(getGrid(mNames[mType]), mAppList); //将状态还原为可编辑 isEditable = true; //将每一个App设为可编辑状态 foreach (SmartAppControl m in getGrid(mNames[mType]).Children) { m.SetControlEditable(true); } } }