public Station DataRowToModel(DataRow row) { Station gpsStation = new Station(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { gpsStation.ID = int.Parse(row["ID"].ToString()); } if (row["RegionDot"] != null) { gpsStation.RegionDot = row["RegionDot"].ToString(); } if (row["RegionName"] != null) { gpsStation.RegionName = row["RegionName"].ToString(); } if (row["RegionType"] != null && row["RegionType"].ToString() != "") { gpsStation.RegionType = new int?(int.Parse(row["RegionType"].ToString())); } if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "") { gpsStation.UpdateTime = new DateTime?(DateTime.Parse(row["UpdateTime"].ToString())); } if (row["StationType"] != null && row["StationType"].ToString() != "") { gpsStation.StationType = new int?(int.Parse(row["StationType"].ToString())); } } return gpsStation; }
public int Add(Station model) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("insert into GpsStation("); stringBuilder.Append("RegionDot,RegionName,RegionType,StationType)"); stringBuilder.Append(" values ("); stringBuilder.Append("@RegionDot,@RegionName,@RegionType,@StationType)"); stringBuilder.Append(";select @@IDENTITY"); string str = stringBuilder.ToString(); List<SqlParam> sqlParams = new List<SqlParam>(); SqlParam sqlParam = new SqlParam() { name = "RegionDot", @value = model.RegionDot }; sqlParams.Add(sqlParam); SqlParam sqlParam1 = new SqlParam() { name = "RegionName", @value = model.RegionName }; sqlParams.Add(sqlParam1); SqlParam sqlParam2 = new SqlParam() { name = "RegionType", @value = model.RegionType }; sqlParams.Add(sqlParam2); SqlParam sqlParam3 = new SqlParam() { name = "StationType", @value = model.StationType }; sqlParams.Add(sqlParam3); DataTable dataTable = RemotingClient.ExecParamSqlByCompress(str, sqlParams); if (dataTable != null && dataTable.Rows.Count > 0) { return 1; } return 0; }
public bool Update(Station model) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("update GpsStation set "); stringBuilder.Append("RegionDot=@RegionDot,"); stringBuilder.Append("RegionName=@RegionName,"); stringBuilder.Append("RegionType=@RegionType,"); stringBuilder.Append("UpdateTime=@UpdateTime,"); stringBuilder.Append("StationType=@StationType"); stringBuilder.Append(" where ID=@ID"); string str = stringBuilder.ToString(); List<SqlParam> sqlParams = new List<SqlParam>(); SqlParam sqlParam = new SqlParam() { name = "RegionDot", @value = model.RegionDot }; sqlParams.Add(sqlParam); SqlParam sqlParam1 = new SqlParam() { name = "RegionName", @value = model.RegionName }; sqlParams.Add(sqlParam1); SqlParam sqlParam2 = new SqlParam() { name = "RegionType", @value = model.RegionType }; sqlParams.Add(sqlParam2); SqlParam sqlParam3 = new SqlParam() { name = "UpdateTime", @value = model.UpdateTime }; sqlParams.Add(sqlParam3); SqlParam sqlParam4 = new SqlParam() { name = "StationType", @value = model.StationType }; sqlParams.Add(sqlParam4); SqlParam sqlParam5 = new SqlParam() { name = "ID", @value = model.ID }; sqlParams.Add(sqlParam5); if (RemotingClient.ExecParamNoQuery(str, sqlParams).ResultCode == (long)0) { return true; } return false; }
public bool Exists(Station model) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("select * from GpsStation"); if (model.ID == 0) { stringBuilder.Append(string.Concat(" where RegionDot like '", model.RegionDot, "'")); stringBuilder.Append(string.Concat(" and RegionName='", model.RegionName, "'")); stringBuilder.Append(string.Concat(" and RegionType='", model.RegionType, "'")); stringBuilder.Append(string.Concat(" and StationType='", model.StationType, "'")); } else { int d = model.ID; stringBuilder.Append(string.Concat(" where ID=", model.ID)); stringBuilder.Append(string.Concat(" and RegionDot like '", model.RegionDot, "'")); stringBuilder.Append(string.Concat(" and RegionName='", model.RegionName, "'")); stringBuilder.Append(string.Concat(" and RegionType='", model.RegionType, "'")); stringBuilder.Append(string.Concat(" and StationType='", model.StationType, "'")); } DataTable dataTable = RemotingClient.ExecSql(stringBuilder.ToString()); if (dataTable != null && dataTable.Rows.Count > 0) { return true; } return false; }
private void execRefRegion(string PathDot, Station models) { this.iRadius = int.Parse(this.numDistance.Value.ToString()); string[] array = PathDot.Split(new char[] { ',' }); this.sRegionStr = string.Concat(new string[] { this.getDotStr(array[0]), "\\", this.getDotStr(array[1]), "\\", this.iRadius.ToString(), "*" }); models.RegionDot = this.sRegionStr; models.RegionName = this.txtRegionName.Text.Trim(); models.RegionType = new int?(0); if (this.cmbType.SelectedValue.ToString() == "-1") { MessageBox.Show("请选择类型"); return; } models.StationType = new int?(int.Parse(this.cmbType.SelectedValue.ToString())); this.sRegionName = models.RegionName; if (this.isAdd && this.dal.Exists("RegionName='" + models.RegionName + "'")) { MessageBox.Show("存在相同的区域命名!", "提示"); return; } if (this.isModify) { DataRow dataRow = this.dt.Rows.Find(int.Parse(this.id)); models.ID = int.Parse(this.id); if (dataRow != null) { if (this.dal.Update(models)) { MessageBox.Show("修改成功", "提示"); dataRow["RegionDot"] = models.RegionDot; dataRow["RegionName"] = models.RegionName; dataRow["RegionType"] = models.RegionType; dataRow["StationType"] = models.StationType; this.LoadData(this.dt); this.sRegionName = models.RegionName; this.ShowLocation(this.sRegionStr); this.wbMap.setPanTool(); this.ClearValue(); this.SetEnableBtn(true); string[] array2 = PathDot.Split(new char[] { ',' }); this.tempsCenterPointX = double.Parse(array2[0]); this.tempsCenterPointY = double.Parse(array2[1]); this.tempsRadius = int.Parse(this.iRadius.ToString()); this.tempsRegionName = this.sRegionName; return; } MessageBox.Show("修改失败", "提示"); return; } } else if (this.isAdd) { if (this.dal.Add(models) > 0) { MessageBox.Show("添加成功", "提示"); if (this.dt != null) { Station model = this.dal.GetModel("RegionName='" + models.RegionName + "'"); DataRow dataRow2 = this.dt.NewRow(); dataRow2["ID"] = model.ID; dataRow2["RegionDot"] = model.RegionDot; dataRow2["RegionName"] = model.RegionName; dataRow2["RegionType"] = model.RegionType; dataRow2["StationType"] = model.StationType; this.dt.Rows.Add(dataRow2); this.pnlOperator.Height = this.pnlSetRegion.Height; this.LoadData(this.dt); this.dgvData.ClearSelection(); this.dgvData.Rows[this.dgvData.RowCount - 1].Selected = true; this.wbMap.setPanTool(); } this.ShowLocation(this.sRegionStr); this.ClearValue(); this.SetEnableBtn(true); return; } MessageBox.Show("添加失败", "提示"); this.ClearValue(); } }
private void btnSave_Click(object sender, EventArgs e) { if (this.isModify || this.isAdd) { if (this.txtRegionDot.Text.Trim() == "") { MessageBox.Show("请拾取坐标", "提示"); return; } if (this.txtRegionName.Text.Trim() == "") { MessageBox.Show("区域名称不能为空", "提示"); return; } if (this.txtRegionName.Text.Trim().IndexOf('^') >= 0) { MessageBox.Show("区域命名中不能包含字符('^')!"); this.txtRegionName.Focus(); return; } Station models = new Station(); if (this.isModify) { this.sPoints = this.txtRegionDot.Text.Trim(); } this.execRefRegion(this.sPoints, models); } }
private int GetStationIndex(Station s) { string res = s.Name.Split('-')[0]; return(int.Parse(res)); }