public void UpdateOfficer(OfficerDTO pOfficerToUpdate)
        {
            //validamos parametro de entrada
            if (pOfficerToUpdate == null) throw new System.ArgumentNullException("pOfficerToUpdate");

            //Validamos los campos del parametro de entrada
            if (pOfficerToUpdate.FirstName == string.Empty
                 || pOfficerToUpdate.LastName == null
                 || pOfficerToUpdate.DocumentTypeId == 0
                 || pOfficerToUpdate.DocumentNumber == null)
                throw new BusinessException("Campos de datos obligatorios estan vacios");

            // obtenemos el objeto a modificar
            Officer mOfficerToUpdate = this.iOfficerDAO.GetById(pOfficerToUpdate.Id);

            // validamos que se haya encontrado el cobrador
            if (mOfficerToUpdate == null) throw new System.InvalidOperationException(string.Format("Cobrador no encontrado", pOfficerToUpdate.Id));
            
            //validamos que el dni sea unico y no halla otro cobrador con el mismo dni
            if ((from a in this.iOfficerDAO.GetAll() where a.DocumentNumber == pOfficerToUpdate.DocumentNumber & a.Id != pOfficerToUpdate.Id select a).Count() > 0)
            {
                throw new BusinessException("Ya existe un cobrador con el dni ingresado, ingrese otro");
            }
            //Si cambio el tipo de documento, se actualiza
            if (pOfficerToUpdate.DocumentTypeId != mOfficerToUpdate.DocumentType.Id )
            {
                mOfficerToUpdate.DocumentType = this.iDocumentTypeDAO.GetById(pOfficerToUpdate.DocumentTypeId);
            }
            Mapper.Map<OfficerDTO, Officer>(pOfficerToUpdate, mOfficerToUpdate);

            // actualizamos la entidad
            this.iOfficerDAO.Update(mOfficerToUpdate);
        }
        public void DeleteOfficer(OfficerDTO pOfficerToDelete)
        {
            //validamos que el Id este en el rango correcto
            if (pOfficerToDelete.Id < -1) throw new System.ArgumentOutOfRangeException("pOfficerToDelete");

            //Se establece la fecha de baja
            pOfficerToDelete.FinishDate = DateTime.Today;

            Officer mOfficerToDelete = Mapper.Map<OfficerDTO, Officer>(pOfficerToDelete);

            // se da de baja el cobrador
            this.iOfficerDAO.Update(mOfficerToDelete);
        }
        public void CreateOfficer(OfficerDTO pOfficerToCreate)
        {
            //Validamos los campos del parametro de entrada
            if (pOfficerToCreate.FirstName == string.Empty                                  
                 || pOfficerToCreate.LastName == null
                 || pOfficerToCreate.DocumentTypeId == 0
                 || pOfficerToCreate.DocumentNumber == null)
                throw new BusinessException("Campos de datos obligatorios estan vacios");

            // creamos el objeto cobrador
            Officer mNewOfficer = Mapper.Map<OfficerDTO, Officer>(pOfficerToCreate);
                  
            //validamos que el dni sea unico y no halla otro cobrador con el mismo dni
            if ((from a in this.iOfficerDAO.GetAll() where a.DocumentNumber == pOfficerToCreate.DocumentNumber select a).Count() > 0)
            {
                throw new BusinessException("Ya existe un cobrador con el codigo ingresado, ingrese otro");
            }
            //Obtengo el tipo de documento
            mNewOfficer.DocumentType = this.iDocumentTypeDAO.GetById(pOfficerToCreate.DocumentTypeId);

            // persistimos la informacion 
            this.iOfficerDAO.Create(mNewOfficer);
        }
        private void bUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                OfficerDTO mOfficer = new OfficerDTO
                {
                    Id = Convert.ToInt32(cbOfficer.SelectedValue)
                };
                PartnerDTO mPartner = new PartnerDTO
                {
                    Id = Convert.ToInt32(tbIdPartnerSelected.Text),
                    FirstName = tbFirstName.Text.ToString(),
                    LastName = tbLastName.Text,
                    DocumentTypeId = Convert.ToInt32(cbDocumentType.SelectedValue),
                    DocumentNumber = mtDocumentNumber.Text,
                    Domicile = tbDomicile.Text,
                    Telephone = tbTelephone.Text,
                    Officer = mOfficer,
                    ValueQuota = Convert.ToSingle(tbValueQuota.Text),
                    QuotaRegime = Convert.ToInt32(cbQuotaRegime.SelectedItem.ToString()),
                    CollectDay = cbDel.SelectedValue.ToString() + "-" + cbAl.SelectedValue.ToString(),
                    CollectDomicile = tbCollectDomicile.Text,
                    StarDate = Convert.ToDateTime(tbStartDate.Text)
                };
                PartnerFacade.UpdatePartner(mPartner);
                this.CleanDataRowSelectDataGridView();
                this.LoadDataGridViewPartner();

                MessageBox.Show("Socio modificado satisfactoriamente", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (BusinessException exception)
            {
                if (tbFirstName.Text == "")
                {
                    FirstNameError.Visible = true;
                }
                if (tbLastName.Text == "")
                {
                    LastNameError.Visible = true;
                }
                if (mtDocumentNumber.Text.Length == 10)
                {
                    for (int indice = 0; indice < mtDocumentNumber.Text.Length; indice++)
                    {
                        if (mtDocumentNumber.Text[indice] == ' ')
                        {
                            DocumentNumberError.Visible = true;
                            indice = mtDocumentNumber.Text.Length;
                        }
                    }
                }
                else
                {
                    DocumentNumberError.Visible = true;
                }
                if (tbDomicile.Text == "")
                {
                    DomicileError.Visible = true;
                }
                if (tbTelephone.Text == "")
                {
                    TelephoneError.Visible = true;
                }
                if (tbValueQuota.Text == "")
                {
                    ValueQuotaError.Visible = true;
                }
                if (tbCollectDomicile.Text == "")
                {
                    CollectDomicileError.Visible = true;
                }
                labelMessaError.Visible = true;
                labelMessaError.Text = exception.Message;
            }
            catch (NullReferenceException exception)
            {
                labelMessaError.Visible = true;
                labelMessaError.Text = exception.Message;
            }
            catch (FormatException)
            {
                labelMessaError.Visible = true;
                labelMessaError.Text = "El formato ingresado es invalido";
            }
            catch (InvalidFormatException exception)
            {
                labelMessaError.Visible = true;
                labelMessaError.Text = exception.Message;
            }
            catch (PartnerException exception)
            {
                labelMessaError.Visible = true;
                labelMessaError.Text = exception.Message;
                DocumentNumberError.Visible = true;
            }
            catch (QuotaException exception)
            {
                labelMessaError.Visible = true;
                labelMessaError.Text = exception.Message;
                ValueQuotaError.Visible = true;
            }
            catch (Exception exception)
            {
                labelMessaError.Visible = true;
                labelMessaError.Text = exception.Message;
            }
        }
 public static void DeleteOfficer(OfficerDTO pOfficer)
 {
     iOfficerSvc.DeleteOfficer(pOfficer);
 }
 public static void UpdateOfficer(OfficerDTO pOfficer)
 {
     iOfficerSvc.UpdateOfficer(pOfficer);
 }
 public static void CreateOfficer(OfficerDTO pOfficer)
 {
     iOfficerSvc.CreateOfficer(pOfficer);
 }
        private void bNew_Click(object sender, EventArgs e)
        {
            try
            {
                ClearErrors();  
                OfficerDTO mOfficer = new OfficerDTO
                {                    
                    FirstName = tbFirstName.Text,
                    LastName = tbLastName.Text,
                    DocumentNumber = tbDocumentNumber.Text,
                    DocumentTypeId = Convert.ToInt32(cbDocumentType.SelectedValue),
                    Domicile = tbDomicile.Text,
                    Telephone = tbPhone.Text,
                    StartDate = DateTime.Today,
                    FinishDate = null
                };
                OfficerFacade.CreateOfficer(mOfficer);
                MessageBox.Show("Cobrador creado satisfactoriamente", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //Recargo la lista de cuentas contables
                LoadDGOfficer();
                CleanScreen();
            }
            catch (BusinessException ex)
            {
                //if ( .Text == string.Empty)
                //{
                //    codeError.Visible = true;
                //}
                //else
                //{
                //    if (tbName.Text == string.Empty)
                //    {
                //        nameError.Visible = true;
                //    }
                //    else
                //    {
                //        if (tbAmount.Text == string.Empty)
                //        {
                //            amountError.Visible = true;
                //        }
                //        else
                //        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                       // }
                  //  }

                //}
            }
           // catch (FormatException)
           // {
               // labelError.Visible = true;
           // }
            catch (DataBaseException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }