{

  int _index = (int)(gridLandList. SelectedRows[0].Cells["id_land"].Value);

  string _commText = "";

  int _result = 0;

  OleDbCommand _command = new OleDbCommand();

  _command. Connection = Program. accessConnection;

  try

  {

  _commText = String. Format("SELECT count(*) FROM t_request WHERE id_land={0}", _index. ToString());

  mandText = _commText;

  _result = (int)_command. ExecuteScalar();

  if (_result > 0)

  {

  MessageBox. Show("На данный земельный участок есть заявки. Сначала необходимо удалить их.", "Ошибка!", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

  return;

  }

  //Сначала удаляем документы, связанные с этим участком, потом участок

  _commText = String. Format("DELETE t_documents.* FROM t_documents WHERE id_land={0}", _index. ToString());

  mandText = _commText;

  _result = _command. ExecuteNonQuery();

  //Теперь удаляем объект

  _commText = String. Format("DELETE t_land.* FROM t_land WHERE id_land={0}", _index. ToString());

  _command = new OleDbCommand(_commText, Program. accessConnection);

  _result = _command. ExecuteNonQuery();

  if (_result == 0) MessageBox. Show("Не удалось удалить запись.", "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

  RetrieveGrids();

  }

  catch (OleDbException _ex)

  {

  MessageBox. Show("Не удалось удалить запись. " + _ex. Message, "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

НЕ нашли? Не то? Что вы ищете?

  }

  }

  public void RetrieveGrids()

  {

  this. realtyDataSet. landListTable. Clear();

  this. landListTableAdapter. Fill(this. realtyDataSet. landListTable);

  gridLandList. Refresh();

  }

  private void EditObject(int _index = 0)

  {

  LandDialog _dlg = new LandDialog(_index);

  if (_dlg. m_Result == Constants. LOAD_OK)

  {

  _dlg. ShowDialog(this);

  RetrieveGrids();

  }

  else

  {

  MessageBox. Show("Ошибка загрузки данных земельного участка.", "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

  }

  }

  private void OnMouseDown(object sender, MouseEventArgs e)

  {

  DataGridView. HitTestInfo hti = gridLandList. HitTest(e. X, e. Y);

  int rowSelected = hti. RowIndex;

  int columnSelected = hti. ColumnIndex;

  if (rowSelected!= -1 && columnSelected!= -1)

  {

  this. gridLandList. CurrentCell = gridLandList. Rows[rowSelected].Cells[columnSelected];

  this. gridLandList. Rows[rowSelected].Selected = true;

  menuLandEdit. Enabled = true;

  menuLandDelete. Enabled = true;

  }

  else if (e. Button == MouseButtons. Right)

  {

  this. gridLandList. CurrentCell = null;

  this. gridLandList. ClearSelection();

  menuLandEdit. Enabled = false;

  menuLandDelete. Enabled = false;

  }

  }

  private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

  {

  DataGridView grid = sender as DataGridView;

  DataGridViewRow row = grid. Rows[e. RowIndex];

  row. Cells["addrString"].Value = Address. GetAddrString(row. Cells["addr_region"].Value as string, row. Cells["addr_district"].Value as string, row. Cells["addr_city"].Value as string, row. Cells["addr_place"].Value as string, row. Cells["addr_street"].Value as string, row. Cells["addr_home"].Value as string, "", "");

  }

  }

}

Файл RealObject. cs

using System;

using System. Collections. Generic;

using ponentModel;

using System. Data;

using System. Drawing;

using System. Linq;

using System. Text;

using System. Windows. Forms;

using System. Data. OleDb;

namespace Realty

{

  public partial class RealObjectList : MyChildForm

  {

  public RealObjectList() : base()

  {

  InitializeComponent();

  }

  public RealObjectList(MainFrame _mainFrame, FrameType _frameType) : base(_mainFrame, _frameType)

  {

  InitializeComponent();

  this. WindowState = FormWindowState. Maximized;

  }

  private void RealObjectList_Load(object sender, EventArgs e)

  {

  try

  {

  this. objectsListTableAdapter. Connection = Program. accessConnection;

  this. objectsListTableAdapter. Fill(this. realtyDataSet. objectsListTable);

  }

  catch (OleDbException ex)

  {

  MessageBox. Show(ex. Message);

  }

  catch (System. Exception ex)

  {

  MessageBox. Show(ex. Message);

  }

  }

  public void RetrieveGrids()

  {

  this. realtyDataSet. objectsListTable. Clear();

  this. objectsListTableAdapter. Fill(this. realtyDataSet. objectsListTable);

  gridObjectList. Refresh();

  }

  private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

  {

  DataGridView grid = sender as DataGridView;

  DataGridViewRow row = grid. Rows[e. RowIndex];

  row. Cells["addrString"].Value = Address. GetAddrString(row. Cells["addr_region"].Value as string, row. Cells["addr_district"].Value as string, row. Cells["addr_city"].Value as string, row. Cells["addr_place"].Value as string, row. Cells["addr_street"].Value as string, row. Cells["addr_home"].Value as string, "", "");

  }

  private void OnAddClick(object sender, EventArgs e)

  {

  EditObject();

  }

  private void OnEditClick(object sender, EventArgs e)

  {

  int _index = (int)(gridObjectList. SelectedRows[0].Cells["id_object"].Value);

  EditObject(_index);

  }

  private void OnDeleteClick(object sender, EventArgs e)

  {

  int _index = (int)(gridObjectList. SelectedRows[0].Cells["id_object"].Value);

  string _commText = "";

  int _result = 0;

  OleDbCommand _command = new OleDbCommand();

  _command. Connection = Program. accessConnection;

  try

  {

  //Здесь сделать проверку на целостность. Если на объект есть заявки, то удалять нельзя

  //Ищем заявки на этот объект

  _commText = String. Format("SELECT count(*) FROM t_request WHERE id_object={0}", _index. ToString());

  mandText = _commText;

  _result = (int)_command. ExecuteScalar();

  if (_result > 0)

  {

  MessageBox. Show("На данный объект есть заявки. Сначала необходимо удалить их.", "Ошибка!", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

  return;

  }

  //Сначала удаляем документы, связанные с этим объектом, потом объект

  _commText = String. Format("DELETE t_documents.* FROM t_documents WHERE id_object={0}", _index. ToString());

  mandText = _commText;

  _result = _command. ExecuteNonQuery();

  //Теперь удаляем объект

  _commText = String. Format("DELETE t_objects.* FROM t_objects WHERE id_object={0}", _index. ToString());

  _command = new OleDbCommand(_commText, Program. accessConnection);

  _result = _command. ExecuteNonQuery();

  if (_result == 0) MessageBox. Show("Не удалось удалить запись.", "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

  RetrieveGrids();

  }

  catch (OleDbException _ex)

  {

  MessageBox. Show("Не удалось удалить запись. " + _ex. Message, "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

  }

  }

  private void OnMouseDown(object sender, MouseEventArgs e)

  {

  DataGridView. HitTestInfo hti = gridObjectList. HitTest(e. X, e. Y);

  int rowSelected = hti. RowIndex;

  int columnSelected = hti. ColumnIndex;

  if (rowSelected!= -1 && columnSelected!= -1)

  {

  this. gridObjectList. CurrentCell = gridObjectList. Rows[rowSelected].Cells[columnSelected];

  this. gridObjectList. Rows[rowSelected].Selected = true;

  menuObjectEdit. Enabled = true;

  menuObjectDelete. Enabled = true;

  }

  else if (e. Button == MouseButtons. Right)

  {

  this. gridObjectList. CurrentCell = null;

  this. gridObjectList. ClearSelection();

  menuObjectEdit. Enabled = false;

  menuObjectDelete. Enabled = false;

  }

  }

  private void EditObject(int _index = 0)

  {

  ObjectDialog _dlg = new ObjectDialog(_index);

  if (_dlg. m_Result == Constants. LOAD_OK)

  {

  _dlg. ShowDialog(this);

  RetrieveGrids();

  }

  else

  {

  MessageBox. Show("Ошибка загрузки данных объекта недвижимости.", "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Exclamation);

  }

  }

  }

}

Файл RequestList. cs

using System;

using System. Collections. Generic;

using ponentModel;

using System. Data;

using System. Drawing;

using System. Linq;

using System. Text;

using System. Windows. Forms;

using System. Data. OleDb;

namespace Realty

{

  public partial class RequestList : MyChildForm

  {

  public int m_IDRequest;

  private Realty. realtyDataSetTableAdapters. landRequestListTableAdapter landRequestAdapter;

  private Realty. realtyDataSetTableAdapters. objectRequestListTableAdapter objectRequestAdapter;

  private Realty. realtyDataSetTableAdapters. buildRequestListTableAdapter buildRequestAdapter;

  public RequestList() : base()

  {

  InitializeComponent();

  }

  public RequestList(MainFrame _mainFrame, FrameType _frameType, int _IDRequest) : base(_mainFrame, _frameType)

Из за большого объема этот материал размещен на нескольких страницах:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19