Esempio n. 1
0
/************************* Add Edit Contract Form Events *****************************************/

        public void Contract_Cell_Click(object sender, DataGridViewCellEventArgs e)
        {
            var dgv = sender as DataGridView;

            if ((e.ColumnIndex == 9) && (e.RowIndex > -1))//-----------------------------------Edit
            {
                #region Edit
                if (_contractForm.GetEndDate().ToShortDateString() != DateTime.Today.ToShortDateString())
                {
                    NewSrvAddr();
                    string addr   = "<No Address>";
                    String addrID = dgv.Rows[e.RowIndex].Cells[0].Value.ToString();
                    try { addr = dgv.Rows[e.RowIndex].Cells["address_col"].Value.ToString(); }
                    catch (NullReferenceException) { }

                    _srvAddrForm = new AddEditSrvAddrForm(this, addr, addrID, e.RowIndex);
                    try { _srvAddrForm.setFields(MContractServices.GetAll(addrID)); }
                    catch (Exception) { }

                    //  _srvAddrForm.Activate();
                    _srvAddrForm.ShowDialog();
                    _srvAddrForm.setDate(_contractForm.GetStartDate());
                    _contractForm.SetTableButtonMetrics(e.RowIndex, addrID);
                }
                else
                {
                    MessageBox.Show("Please specify the end date of the contract.", "Incomplete Contract", MessageBoxButtons.OKCancel);
                }
                #endregion
            }
            if ((e.ColumnIndex == 8) && (e.RowIndex > -1))// ----------------------------------Room
            {
                #region Room
                //int k = arg.RowIndex;
                String addrID = dgv.Rows[e.RowIndex].Cells["idCol"].Value.ToString();
                NewSrvAddr();
                _roomForm = new AddEditRoomForm(this, addrID, e.RowIndex);
                _roomForm.Activate();
                _roomForm.ShowDialog();

                _contractForm.SetTableButtonMetrics(e.RowIndex, addrID);
                return;

                #endregion
            }

            if ((e.ColumnIndex == 10) && (e.RowIndex > -1))//-----------------------------------Remove
            {
                #region Remove
                try
                {
                    string id = dgv.Rows[e.RowIndex].Cells["idCol"].Value.ToString();
                    MServiceAddress.Delete(id, "Service_Address", "service_addres_id");
                }
                catch (Exception) { }
                dgv.Rows.RemoveAt(e.RowIndex);
                #endregion
            }


            else//---------------------------------------------------------------------------Other
            {
                return;
            }
        }
        /************************* Add Edit Contract Form Events *****************************************/
        public void Contract_Cell_Click(object sender, DataGridViewCellEventArgs e)
        {
            var dgv = sender as DataGridView;
            if ((e.ColumnIndex == 9) && (e.RowIndex > -1))//-----------------------------------Edit
            {
                #region Edit
                if (_contractForm.GetEndDate().ToShortDateString() != DateTime.Today.ToShortDateString())
                {
                    NewSrvAddr();
                    string addr = "<No Address>";
                    String addrID = dgv.Rows[e.RowIndex].Cells[0].Value.ToString();
                    try { addr = dgv.Rows[e.RowIndex].Cells["address_col"].Value.ToString(); }
                    catch (NullReferenceException) { }

                    _srvAddrForm = new AddEditSrvAddrForm(this, addr, addrID, e.RowIndex);
                    try { _srvAddrForm.setFields(MContractServices.GetAll(addrID)); }
                    catch (Exception) { }

                  //  _srvAddrForm.Activate();
                    _srvAddrForm.ShowDialog();
                    _srvAddrForm.setDate(_contractForm.GetStartDate());
                    _contractForm.SetTableButtonMetrics(e.RowIndex, addrID);
                }
                else
                    MessageBox.Show("Please specify the end date of the contract.", "Incomplete Contract", MessageBoxButtons.OKCancel);
                #endregion
            }
            if ((e.ColumnIndex == 8) && (e.RowIndex > -1))// ----------------------------------Room
               {
               #region Room
               //int k = arg.RowIndex;
               String addrID = dgv.Rows[e.RowIndex].Cells["idCol"].Value.ToString();
                NewSrvAddr();
                _roomForm = new AddEditRoomForm(this, addrID, e.RowIndex);
                _roomForm.Activate();
                _roomForm.ShowDialog();

                _contractForm.SetTableButtonMetrics(e.RowIndex, addrID);
                return;
               #endregion
               }

            if ((e.ColumnIndex == 10) && (e.RowIndex > -1))//-----------------------------------Remove
            {
                #region Remove
                try
                {
                    string id = dgv.Rows[e.RowIndex].Cells["idCol"].Value.ToString();
                    MServiceAddress.Delete(id, "Service_Address", "service_addres_id");
                }
                catch (Exception) { }
                dgv.Rows.RemoveAt(e.RowIndex);
                #endregion
            }

            else//---------------------------------------------------------------------------Other
                return;
        }