/// <summary> /// insert Or Update App Settings /// </summary> private void InsertOrUpdateAppSettings() { SqlDao.DbHelper helper = DatabaseOPtionHelper.GetInstance();; string sql = string.Empty; NameValueCollection collection = ConfigurationManager.AppSettings; string[] keys = collection.AllKeys; foreach (string key in keys) { Config config = null; sql = helper.getSelectSql("config", null, "client_id ='" + ConfigurationHelper.GetConfig(ConfigItemName.clientId.ToString()) + "' and config_name = '" + key + "'", null, null, null, 1); List <Config> configs = helper.select <Config>(sql); if (configs != null && configs.Count > 0) { if (configs[0] != null) { config = configs[0]; if (config.configValue != collection[key].ToString()) { config.configValue = collection[key].ToString(); config.syncTime = DateTimeHelper.ConvertDateTimeToInt(DateTime.Now); config.updateTime = DateTimeHelper.getCurrentDateTime(); if (App.currentUser != null) { config.updateUserId = config.addUserId; config.updateUserName = config.addUserName; } } helper.update(config); } else { //conveter error } } else { config = new Config { id = Guid.NewGuid().ToString(), addtime = DateTimeHelper.getCurrentDateTime(), configName = key, clientId = ConfigurationHelper.GetConfig(ConfigItemName.clientId.ToString()), configValue = collection[key].ToString(), configType = (int)ConfigType.ClientAppConfig }; config.updateTime = config.addtime; config.syncTime = DateTimeHelper.ConvertDateTimeToInt(DateTime.Now); if (App.currentUser != null) { config.addUserId = App.currentUser.id; config.addUserName = App.currentUser.name; config.updateUserId = config.addUserId; config.updateUserName = config.addUserName; } helper.insert(config); } } }
private void saveBtn_Click(object sender, RoutedEventArgs e) { //抓图 //if (isInitSDK && isPreviewSuccess) { // CameraHelper.captureJpeg(Guid.NewGuid().ToString()+".jpg",currCameraId,1); // CameraHelper.captureBmp(Guid.NewGuid().ToString() + ".bmp",currCameraId); //}else{ // ConsoleHelper.writeLine("captureJpeg failured"); //} if (!IsInitialized) { MessageBox.Show("摄像头初始化失败!"); return; } if (!isPreviewSuccess) { MessageBox.Show("保存摄像头之前必须先预览成功!"); return; } if (checkInput()) { String condition = String.Empty; String sql = string.Empty; if (!String.IsNullOrEmpty(mId)) { //update mCameraInfo.syncTime = (int)DateTimeHelper.GetTimeStamp(); mCameraInfo.ip = this.IpTB.Text.Trim(); mCameraInfo.port = this.portTB.Text.Trim(); mCameraInfo.userName = this.userNameTB.Text.Trim(); mCameraInfo.password = this.pwdTB.Text.Trim(); int res = DatabaseOPtionHelper.GetInstance().update(mCameraInfo); if (res > 0) { MessageBox.Show("修改成功!"); this.Close(); } else { MessageBox.Show("修改失败!"); return; } } else { //insert CameraInfo camera = new CameraInfo(); string cid = ConfigurationHelper.GetConfig(ConfigItemName.clientId.ToString()); condition = CameraInfoEnum.client_id.ToString() + "=" + Constract.valueSplit + cid + Constract.valueSplit + " and " + CameraInfoEnum.ip.ToString() + "=" + Constract.valueSplit + IpTB.Text.ToString() + Constract.valueSplit + " and " + CameraInfoEnum.port.ToString() + "=" + Constract.valueSplit + this.portTB.Text.ToString() + Constract.valueSplit; sql = DatabaseOPtionHelper.GetInstance().getSelectSqlNoSoftDeleteCondition(DatabaseOPtionHelper.GetInstance().getTableName(camera), null, condition, null, null, null, 1, 0); SqlDao.DbHelper optionHelper = DatabaseOPtionHelper.GetInstance(); List <CameraInfo> list = optionHelper.select <CameraInfo>(sql); if (list.Count > 0) { MessageBox.Show("该摄像头已经存在,不要再添加拉!"); return; } else { camera.clientId = cid; camera.companyId = ConfigurationHelper.GetConfig(ConfigItemName.companyId.ToString()); camera.status = 0; camera.isDelete = 0; camera.syncTime = 0; camera.ip = this.IpTB.Text.Trim(); camera.port = this.portTB.Text.Trim(); camera.userName = this.userNameTB.Text.Trim(); camera.password = this.pwdTB.Text.Trim(); camera.id = Guid.NewGuid().ToString(); int res = optionHelper.insert(camera); if (res > 0) { MessageBox.Show("保存成功!"); this.Close(); } else { MessageBox.Show("保存失败!"); return; } } } } }