_result = LoadData(userAdapter);

  return _result;

  }

  private int LoadData(OleDbDataAdapter _userAdapter)

  {

  DataSet userDataSet = new DataSet();

  _userAdapter. Fill(userDataSet, "t_users");

  if (userDataSet. Tables["t_users"].Rows. Count == 0) return Constants. LOAD_NO_DATA;

  m_IDUser = (int)userDataSet. Tables["t_users"].Rows[0]["id_user"];

  m_Login = userDataSet. Tables["t_users"].Rows[0]["login"] as string;

  m_FirstName = userDataSet. Tables["t_users"].Rows[0]["first_name"] as string;

  m_LastName = userDataSet. Tables["t_users"].Rows[0]["last_name"] as string;

  m_SecondName = userDataSet. Tables["t_users"].Rows[0]["second_name"] as string;

  m_Password = userDataSet. Tables["t_users"].Rows[0]["password"] as string;

  m_Position = (int)userDataSet. Tables["t_users"].Rows[0]["position"];

  m_Permission = (int)userDataSet. Tables["t_users"].Rows[0]["permission"];

  m_PositionStr = userDataSet. Tables["t_users"].Rows[0]["posStr"] as string;

  m_FullPositionStr = userDataSet. Tables["t_users"].Rows[0]["fullPosStr"] as string;

  m_PermissionStr = userDataSet. Tables["t_users"].Rows[0]["permStr"] as string;

  return Constants. LOAD_OK;

  }

  public int SaveDataToDB()

  {

  try

  {

  string _commText = "";

  if (m_IDUser == 0)

  {

  m_IDUser = GetNewID();

  _commText = String. Format("INSERT INTO t_users ([id_user],[login],[password],[last_name],[first_name],[second_name],[position],[permission]) VALUES ({0},'{1}','{2}','{3}','{4}','{5}',{6},{7})", m_IDUser. ToString(), m_Login, m_Password, m_LastName, m_FirstName, m_SecondName, m_Position, m_Permission);

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

  }

  else

  {

  if (m_ChangePass) _commText = String. Format("UPDATE t_users SET [login]='{1}',[password]='{2}',[last_name]='{3}',[first_name]='{4}',[second_name]='{5}',[position]={6},[permission]={7} WHERE [id_user]={0}", m_IDUser. ToString(), m_Login, m_Password, m_LastName, m_FirstName, m_SecondName, m_Position, m_Permission);

  else _commText = String. Format("UPDATE t_users SET [login]='{1}',[last_name]='{3}',[first_name]='{4}',[second_name]='{5}',[position]={6},[permission]={7} WHERE [id_user]={0}", m_IDUser. ToString(), m_Login, m_Password, m_LastName, m_FirstName, m_SecondName, m_Position, m_Permission);

  }

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

  int _result = _command. ExecuteNonQuery();

  if (_result == 1) return Constants. LOAD_OK;

  else return Constants. LOAD_NO_DATA;

  }

  catch (OleDbException _ex)

  {

  return Constants. LOAD_NO_DATA;

  }

  }

  private int GetNewID()

  {

  int _newID = 0;

  try

  {

  OleDbCommand _command = new OleDbCommand("SELECT Max(id_user) FROM t_users", Program. accessConnection);

  mandType = CommandType. Text;

  object _obj = _command. ExecuteScalar();

  _newID = ((_obj. Equals(DBNull. Value)) ? 0 : (int)_obj) + 1;

  return _newID;

  }

  catch (OleDbException _ex)

  {

  return Constants. LOAD_NO_DATA;

  }

  }

  }

}

Файл ClientList. 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 ClientList : MyChildForm

  {

  public ClientList() : base()

  {

  InitializeComponent();

  }

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

  {

  InitializeComponent();

  this. WindowState = FormWindowState. Maximized;

  }

  private void ClientList_Load(object sender, EventArgs e)

  {

  try

  {

  this. clientListTableAdapter. Connection = Program. accessConnection;

  this. clientListTableAdapter. Fill(this. realtyDataSet. clientListTable);

  }

  catch (OleDbException ex)

  {

  MessageBox. Show(ex. Message);

  }

  catch (System. Exception ex)

  {

  MessageBox. Show(ex. Message);

  }

  }

  public void RetrieveGrids()

  {

  this. realtyDataSet. clientListTable. Clear();

  this. clientListTableAdapter. Fill(this. realtyDataSet. clientListTable);

  gridClientList. Refresh();

  }

  private void OnAddClick(object sender, EventArgs e)

  {

  EditClient();

  }

  private void OnEditClick(object sender, EventArgs e)

  {

  int _index = (int)(gridClientList. SelectedRows[0].Cells["id_client"].Value);

  EditClient(_index);

  }

  private void OnDeleteClick(object sender, EventArgs e)

  {

  int _index = (int)(gridClientList. SelectedRows[0].Cells["id_client"].Value);

  string _commText = "";

  int _result = 0;

  OleDbCommand _command = new OleDbCommand();

  _command. Connection = Program. accessConnection;

  try

  {

  _commText = String. Format("SELECT count(*) FROM t_documents WHERE id_client={0} AND id_land <> 0", _index. ToString());

  mandText = _commText;

  _result = (int)_command. ExecuteScalar();

  if (_result > 0)

  {

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

  return;

  }

  //Ищем заявки этого клиента

  _commText = String. Format("SELECT count(*) FROM t_request WHERE id_client={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_client={0}", _index. ToString());

  mandText = _commText;

  _result = _command. ExecuteNonQuery();

  //Удаляем непосредственно клиента

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

  mandText = _commText;

  _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 = gridClientList. HitTest(e. X, e. Y);

  int rowSelected = hti. RowIndex;

  int columnSelected = hti. ColumnIndex;

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

  {

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

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

  menuClientEdit. Enabled = true;

  menuClientDelete. Enabled = true;

  }

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

  {

  this. gridClientList. CurrentCell = null;

  this. gridClientList. ClearSelection();

  menuClientEdit. Enabled = false;

  menuClientDelete. Enabled = false;

  }

  }

  private void EditClient(int _index = 0)

  {

  ClientDialog _dlg = new ClientDialog(_index);

  if (_dlg. m_Result == Constants. LOAD_OK)

  {

  _dlg. ShowDialog(this);

  RetrieveGrids();

  }

  else

  {

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

  }

  }

  }

}

Файл LandList. 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 LandList : MyChildForm

  {

  public LandList() : base()

  {

  InitializeComponent();

  }

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

  {

  InitializeComponent();

  this. WindowState = FormWindowState. Maximized;

  }

  private void LandList_Load(object sender, EventArgs e)

  {

  try

  {

  this. landListTableAdapter. Connection = Program. accessConnection;

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

  }

  catch (OleDbException ex)

  {

  MessageBox. Show(ex. Message);

  }

  catch (System. Exception ex)

  {

  MessageBox. Show(ex. Message);

  }

  }

  private void OnAddClick(object sender, EventArgs e)

  {

  EditObject();

  }

  private void OnEditClick(object sender, EventArgs e)

  {

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

  EditObject(_index);

  }

  private void OnDeleteClick(object sender, EventArgs e)

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