/// <summary> /// /// </summary> /// <param name="ID"> </param> /// <returns></returns> public static Entity.Area GetAreaByID(int ID) { Entity.Area entity = null; DBOperatorBase db = new DataBase(); IDBTypeElementFactory dbFactory = db.GetDBTypeElementFactory(); try { IDataReader dataReader = db.ExecuteReader(Config.con, CommandType.Text, "Select * from [Area] where ID='" + ID + "'", null); while (dataReader.Read()) { entity = new Entity.Area(); entity.ID = DataHelper.ParseToInt(dataReader["ID"].ToString()); entity.AreaCode = DataHelper.ParseToInt(dataReader["AreaCode"].ToString()); entity.FullName = dataReader["FullName"].ToString(); entity.LetterCode = dataReader["LetterCode"].ToString(); entity.ShortName = dataReader["ShortName"].ToString(); entity.IsDelete = DataHelper.ParseToInt(dataReader["IsDelete"].ToString()); entity.OrderID = DataHelper.ParseToInt(dataReader["OrderID"].ToString()); } } catch (Exception ex) { } finally { db.Conn.Close(); } return(entity); }
public static int UpdateArea(Entity.Area entity) { int iReturn = 0; DBOperatorBase db = new DataBase(); IDBTypeElementFactory dbFactory = db.GetDBTypeElementFactory(); SqlTransactionHelper thelper = new SqlTransactionHelper(DAL.Config.con); IDbTransaction trans = thelper.StartTransaction(); try { IDbDataParameter[] prams = { dbFactory.MakeInParam("@ID", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.ID.GetType().ToString()), entity.ID, 32), dbFactory.MakeInParam("@AreaCode", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.AreaCode.GetType().ToString()), entity.AreaCode, 32), dbFactory.MakeInParam("@FullName", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.FullName.GetType().ToString()), entity.FullName, 20), dbFactory.MakeInParam("@LetterCode", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.LetterCode.GetType().ToString()), entity.LetterCode, 10), dbFactory.MakeInParam("@ShortName", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.ShortName.GetType().ToString()), entity.ShortName, 20), dbFactory.MakeInParam("@IsDelete", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.IsDelete.GetType().ToString()), entity.IsDelete, 32), dbFactory.MakeInParam("@OrderID", DBTypeConverter.ConvertCsTypeToOriginDBType(entity.OrderID.GetType().ToString()), entity.OrderID, 32) }; iReturn = db.ExecuteNonQueryTrans(trans, CommandType.StoredProcedure, "proc_Area_Update", prams); thelper.CommitTransaction(trans); iReturn = 1; } catch (Exception ex) { thelper.RollTransaction(trans); iReturn = 0; } finally { db.Conn.Close(); } return(iReturn); }
private WeatherWebServiceSoapClient weatherClient; //获取气象信息的WebService对象 /// <summary> /// 获得当前保存地区 /// </summary> /// <returns></returns> public Entity.Area GetCurrentArea() { var file = new FileInfo(_filePath); Entity.Area result; if (!file.Exists) { //文件不存在就返回一个默认值,默认是成都 result = new Entity.Area(); result.ID = 250; result.Name = "成都"; result.ZoneID = 23; //area.Zone = new Models.Zone() { ID = 23, Name = "四川" }; result.AreaCode = "56294"; } else { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Entity.Area)); using (var stream = file.Open(FileMode.Open, FileAccess.Read)) { result = (Entity.Area)ser.ReadObject(stream); } } return(result); }
//窗体加载 private void Window_Loaded(object sender, RoutedEventArgs e) { #region 省份 this._area = _balWeather.GetCurrentArea(); LoadAreaData(); #endregion ControlHelper.Instance.SetBackground(this.mainBoder, Entity.App.AppBgImg); this._xml = new XmlHelper(Entity.App.Config); for (int i = 1; i < 20; i++) { this.cboMinute.Items.Add(i); } this.cboMinute.SelectedIndex = 0; //自动启动 if (Sys.IsAutoStartup()) { this.chkAutoRun.IsChecked = true; } this.tbxBgImg.Text = _xml.SelectNodeText("Configuration/AppBgImg"); this.tbxLockBgImg.Text = _xml.SelectNodeText("Configuration/LockBgImg"); this.chkMinToTray.IsChecked = Entity.App.MinToTray;// _xml.SelectNodeText("Configuration/MinToTray") == "1" ? true : false; this.chkSaveLog.IsChecked = Entity.App.SaveLog; this.cboMinute.SelectedValue = Entity.App.LockMinute; }
/// <summary> /// 从DataSet中加载城市信息 /// </summary> /// <param name="ds"></param> void InitZoneFromDataSet(DataSet ds) { this.ZoneList = new ObservableCollection <Entity.Zone>(); this.AreaList = new ObservableCollection <Entity.Area>(); var dtZone = ds.Tables[0]; var dtArea = ds.Tables[1]; this.ZoneList.Clear(); foreach (DataRow dr in dtZone.Rows) { var zone = new Entity.Zone() { ID = Convert.ToInt32(dr["ID"]), Name = dr["Zone"].ToString(), }; var drAreas = dtArea.Select("ZoneID=" + zone.ID); foreach (DataRow drArea in drAreas) { var area = new Entity.Area() { ID = Convert.ToInt32(drArea["ID"]), ZoneID = Convert.ToInt32(drArea["ZoneID"]), Name = drArea["Area"].ToString(), AreaCode = drArea["AreaCode"].ToString() }; this.AreaList.Add(area); } this.ZoneList.Add(zone); } }
private void btnOK_Click(object sender, RoutedEventArgs e) { if (this.btnOK.Content.ToString() == "确定") { this.Close(); return; } Sys.AutoStartup((bool)this.chkAutoRun.IsChecked); Entity.App.MinToTray = (this.chkMinToTray.IsChecked == true); Entity.App.LockMinute = Convert.ToInt32(this.cboMinute.Text); _xml.SetXmlNodeValue("Configuration/LockMinute", this.cboMinute.Text); _xml.SetXmlNodeValue("Configuration/SaveLog", this.chkSaveLog.IsChecked == true ? "1" : "0"); Entity.App.SaveLog = this.chkSaveLog.IsChecked == true; try { string path = this.tbxBgImg.Text.Trim(); if (!System.IO.File.Exists(path) || (!path.ToLower().EndsWith(".jpg") && !path.ToLower().EndsWith(".png"))) { this.tbxBgImg.Text = ""; path = ""; } _xml.SetXmlNodeValue("Configuration/AppBgImg", path); path = this.tbxLockBgImg.Text.Trim(); if (!System.IO.File.Exists(path) || (!path.ToLower().EndsWith(".jpg") && !path.ToLower().EndsWith(".png"))) { this.tbxLockBgImg.Text = ""; path = ""; } _xml.SetXmlNodeValue("Configuration/LockBgImg", path); _xml.SetXmlNodeValue("Configuration/MinToTray", Entity.App.MinToTray ? "1" : "0"); _xml.Save(); //保存城市信息 this._area = (Entity.Area) this.chkCity.SelectedItem; if (this._area != null) { _balWeather.SaveCurrentArea(this._area); } MessageBox.Show("保存成功,重启后生效!", "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); } catch (Exception ex) { Log.SaveLog("Config btnOK_Click", ex.ToString()); MessageBox.Show("保存失败!", "警告", MessageBoxButton.OK, MessageBoxImage.Error); } }
protected void btn_save_Click(object sender, EventArgs e) { string msg = checkInput(); if (msg != "") { Alert.Show(msg); return; } else { Entity.Area entity = new Entity.Area(); entity.FullName = txt_name.Text.Trim(); // = ds.Tables[0].Rows[0]["单位全称"].ToString(); entity.ShortName = txt_jc.Text.Trim(); // = ds.Tables[0].Rows[0]["单位曾用名全称"].ToString(); entity.LetterCode = txt_bm.Text.Trim(); entity.OrderID = int.Parse(Orderid.Text.ToString()); entity.AreaCode = int.Parse(txt_areacode.Text.Trim());// = ds.Tables[0].Rows[0]["单位法人代码"].ToString(); entity.IsDelete = int.Parse(CheckStop.SelectedValue.ToString()); if (string.IsNullOrEmpty(sGuid)) { //Add int success = DAL.Area.AddArea(entity); if (success == 1) { Alert.ShowInTop(" 保存成功!", MessageBoxIcon.Information); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { Alert.ShowInTop(" 保存失败!", MessageBoxIcon.Warning); } } else { //Update entity.ID = int.Parse(sGuid); int success = DAL.Area.UpdateArea(entity); if (success == 1) { Alert.ShowInTop(" 修改成功!", MessageBoxIcon.Information); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { Alert.ShowInTop(" 修改失败!", MessageBoxIcon.Warning); } } } }
private void LoadData(string sId) { if (sId != string.Empty) { Entity.Area entity = DAL.Area.GetAreaByID(int.Parse(sId)); txt_name.Text = entity.FullName; //txt_pwNO.Text = ds.Tables[0].Rows[0]["排污权证号"].ToString(); txt_jc.Text = entity.ShortName; txt_areacode.Text = entity.AreaCode.ToString(); txt_bm.Text = entity.LetterCode; CheckStop.SelectedValue = entity.IsDelete.ToString(); Orderid.Text = entity.OrderID.ToString(); } }
public void SaveCurrentArea(Entity.Area area) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Entity.Area)); var file = new FileInfo(_filePath); FileStream stream; if (file.Exists) { stream = file.Open(FileMode.Truncate, FileAccess.Write); } else { stream = file.Open(FileMode.Create, FileAccess.Write); } using (stream) { ser.WriteObject(stream, area); } }