/// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of CRecep_sample</returns>
        internal List <CRecep_sample> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List <CRecep_sample> list = new List <CRecep_sample>();

            while (dataReader.Read())
            {
                CRecep_sample businessObject = new CRecep_sample();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>CRecep_sample business object</returns>
        public CRecep_sample SelectByPrimaryKey(CRecep_sampleKeys keys)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

            sqlCommand.CommandText = "public.sp_recep_sample_SelectByPrimaryKey";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.Add(new NpgsqlParameter("p_idrecep_sample", NpgsqlDbType.Bigint, 8, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idrecep_sample));


                MainConnection.Open();

                NpgsqlDataReader dataReader = sqlCommand.ExecuteReader();

                if (dataReader.Read())
                {
                    CRecep_sample businessObject = new CRecep_sample();

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("CRecep_sample::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(CRecep_sample businessObject, IDataReader dataReader)
        {
            businessObject.Idrecep_sample = dataReader.GetInt64(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Idrecep_sample.ToString()));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Cod_recep_sample.ToString())))
            {
                businessObject.Cod_recep_sample = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Cod_recep_sample.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Date_reception.ToString())))
            {
                businessObject.Date_reception = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Date_reception.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Type_post.ToString())))
            {
                businessObject.Type_post = dataReader.GetChar(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Type_post.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Phone_client.ToString())))
            {
                businessObject.Phone_client = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Phone_client.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Idcompany.ToString())))
            {
                businessObject.Idcompany = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Idcompany.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Idcontact1.ToString())))
            {
                businessObject.Idcontact1 = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Idcontact1.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Idcontact2.ToString())))
            {
                businessObject.Idcontact2 = (short?)dataReader.GetInt16(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Idcontact2.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Cod_serie.ToString())))
            {
                businessObject.Cod_serie = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Cod_serie.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Usernew.ToString())))
            {
                businessObject.Usernew = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Usernew.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Datenew.ToString())))
            {
                businessObject.Datenew = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Datenew.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Useredit.ToString())))
            {
                businessObject.Useredit = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Useredit.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Dateedit.ToString())))
            {
                businessObject.Dateedit = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Dateedit.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Status.ToString())))
            {
                businessObject.Status = dataReader.GetBoolean(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Status.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Date_result.ToString())))
            {
                businessObject.Date_result = dataReader.GetDateTime(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Date_result.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Cod_type_sample.ToString())))
            {
                businessObject.Cod_type_sample = dataReader.GetString(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Cod_type_sample.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Total_amount.ToString())))
            {
                businessObject.Total_amount = dataReader.GetDecimal(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Total_amount.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Total_igv.ToString())))
            {
                businessObject.Total_igv = dataReader.GetDecimal(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Total_igv.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Total_amount_igv.ToString())))
            {
                businessObject.Total_amount_igv = dataReader.GetDecimal(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Total_amount_igv.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Amortization.ToString())))
            {
                businessObject.Amortization = dataReader.GetDecimal(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Amortization.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Flag_isprice.ToString())))
            {
                businessObject.Flag_isprice = dataReader.GetBoolean(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Flag_isprice.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Discount.ToString())))
            {
                businessObject.Discount = dataReader.GetDecimal(dataReader.GetOrdinal(CRecep_sample.CRecep_sampleFields.Discount.ToString()));
            }
        }
        /// <summary>
        /// insert new row in the table
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <returns>true of successfully insert</returns>
        public bool Insert(CRecep_sample businessObject)
        {
            NpgsqlCommand sqlCommand = new NpgsqlCommand();

            sqlCommand.CommandText = "public.sp_recep_sample_Insert";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.AddWithValue("p_idrecep_sample", businessObject.Idrecep_sample);
                sqlCommand.Parameters["p_idrecep_sample"].NpgsqlDbType = NpgsqlDbType.Bigint;
                sqlCommand.Parameters["p_idrecep_sample"].Direction    = ParameterDirection.InputOutput;

                sqlCommand.Parameters.AddWithValue("p_cod_recep_sample", businessObject.Cod_recep_sample);
                sqlCommand.Parameters["p_cod_recep_sample"].NpgsqlDbType = NpgsqlDbType.Varchar;
                sqlCommand.Parameters.AddWithValue("p_date_reception", businessObject.Date_reception);
                sqlCommand.Parameters["p_date_reception"].NpgsqlDbType = NpgsqlDbType.Timestamp;
                sqlCommand.Parameters.AddWithValue("p_type_post", businessObject.Type_post);
                sqlCommand.Parameters["p_type_post"].NpgsqlDbType = NpgsqlDbType.Char;
                sqlCommand.Parameters.AddWithValue("p_phone_client", businessObject.Phone_client);
                sqlCommand.Parameters["p_phone_client"].NpgsqlDbType = NpgsqlDbType.Varchar;
                sqlCommand.Parameters.AddWithValue("p_idcompany", businessObject.Idcompany);
                sqlCommand.Parameters["p_idcompany"].NpgsqlDbType = NpgsqlDbType.Smallint;
                sqlCommand.Parameters.AddWithValue("p_idcontact1", businessObject.Idcontact1);
                sqlCommand.Parameters["p_idcontact1"].NpgsqlDbType = NpgsqlDbType.Smallint;
                sqlCommand.Parameters.AddWithValue("p_idcontact2", businessObject.Idcontact2);
                sqlCommand.Parameters["p_idcontact2"].NpgsqlDbType = NpgsqlDbType.Smallint;
                sqlCommand.Parameters.AddWithValue("p_cod_serie", businessObject.Cod_serie);
                sqlCommand.Parameters["p_cod_serie"].NpgsqlDbType = NpgsqlDbType.Varchar;
                sqlCommand.Parameters.AddWithValue("p_usernew", businessObject.Usernew);
                sqlCommand.Parameters["p_usernew"].NpgsqlDbType = NpgsqlDbType.Varchar;
                sqlCommand.Parameters.AddWithValue("p_datenew", businessObject.Datenew);
                sqlCommand.Parameters["p_datenew"].NpgsqlDbType = NpgsqlDbType.Date;
                sqlCommand.Parameters.AddWithValue("p_useredit", businessObject.Useredit);
                sqlCommand.Parameters["p_useredit"].NpgsqlDbType = NpgsqlDbType.Varchar;
                sqlCommand.Parameters.AddWithValue("p_dateedit", businessObject.Dateedit);
                sqlCommand.Parameters["p_dateedit"].NpgsqlDbType = NpgsqlDbType.Date;
                sqlCommand.Parameters.AddWithValue("p_status", businessObject.Status);
                sqlCommand.Parameters["p_status"].NpgsqlDbType = NpgsqlDbType.Boolean;
                sqlCommand.Parameters.AddWithValue("p_date_result", businessObject.Date_result);
                sqlCommand.Parameters["p_date_result"].NpgsqlDbType = NpgsqlDbType.Timestamp;
                sqlCommand.Parameters.AddWithValue("p_cod_type_sample", businessObject.Cod_type_sample);
                sqlCommand.Parameters["p_cod_type_sample"].NpgsqlDbType = NpgsqlDbType.Varchar;
                sqlCommand.Parameters.AddWithValue("p_total_amount", businessObject.Total_amount);
                sqlCommand.Parameters["p_total_amount"].NpgsqlDbType = NpgsqlDbType.Numeric;
                sqlCommand.Parameters.AddWithValue("p_total_igv", businessObject.Total_igv);
                sqlCommand.Parameters["p_total_igv"].NpgsqlDbType = NpgsqlDbType.Numeric;
                sqlCommand.Parameters.AddWithValue("p_total_amount_igv", businessObject.Total_amount_igv);
                sqlCommand.Parameters["p_total_amount_igv"].NpgsqlDbType = NpgsqlDbType.Numeric;
                sqlCommand.Parameters.AddWithValue("p_amortization", businessObject.Amortization);
                sqlCommand.Parameters["p_amortization"].NpgsqlDbType = NpgsqlDbType.Numeric;
                sqlCommand.Parameters.AddWithValue("p_flag_isprice", businessObject.Flag_isprice);
                sqlCommand.Parameters["p_flag_isprice"].NpgsqlDbType = NpgsqlDbType.Boolean;
                sqlCommand.Parameters.AddWithValue("p_discount", businessObject.Discount);
                sqlCommand.Parameters["p_discount"].NpgsqlDbType = NpgsqlDbType.Numeric;


                MainConnection.Open();

                sqlCommand.ExecuteNonQuery();
                businessObject.Idrecep_sample = Convert.ToInt64(sqlCommand.Parameters["p_idrecep_sample"].Value);

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("CRecep_sample::Insert::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Ejemplo n.º 5
0
        protected override void Limpiar_Campos()
        {
            txIdrecep_sample.Text = "";
            IDCompany = 0;
            cbCompany.EditValue = null;
            tbClientRuc.Text = "";
            tbClientDomicile.Text = "";
            tbClientPhone.Text = "";
            ckDispatchPerson.Checked = false;
            ckDispatchCurier.Checked = false;
            ckDispatchTransport.Checked = false;
            ckDispatchFax.Checked = false;
            tbSubTotalAmount.Text = "";
            tbTotalIgv.Text = "";
            tbTotalAmount.Text = "";
            totalAmount = 0;
            tbAmortization.Text = "";
            tbResidue.Text = "";
            deReception.DateTime = DateTime.Now;
            deHourReception.EditValue = DateTime.Now;
            deResult.Text = "";
            deHourResult.Text = "";
            tbCod_recep_sample.Text = "";

            deHourResult.Time = DateTime.Now;
            tbNumDays.Value = 0;
            deResult.EditValue = null;
            deHourResult.EditValue = null;

            tpRightReports.PageVisible = false;
            tpRightAttach.PageVisible = false;
            tpRightProgram.PageVisible = false;

            lstItemsSelAttach.Clear();
            lstItemsSelReport.Clear();
            lstItemsSelProgram.Clear();

            InitDatatable();
            InitDataControls();

            gcContact.DataSource = null;
            gcReport.DataSource = null;
            gcAttachFile.DataSource = null;
            gcProgram.DataSource = null;
            ClearElemColumns();

            ucSignReception.Clear();

            oRecep_sample = null;
            oPrice = null;
            oPrice_version = null;
        }
Ejemplo n.º 6
0
        protected override bool Grabar()
        {
            if (Son_Datos_Correctos() &&
               (MessageBox.Show("Desea grabar el documento actual?", "Grabar Registro", MessageBoxButtons.YesNo) == DialogResult.Yes))
            {

                if (Grabar_Registro())
                {
                    // --- show tappages
                    tpRightReports.PageVisible = true;
                    tpRightAttach.PageVisible = true;
                    tpRightProgram.PageVisible = true;

                    // --- show dialog, print tickets
                    MessageBox.Show("Guardado exitosamente.");

                    ///recuperar registro como estado de busqueda
                    ///
                    long idrecep_sample = oRecep_sample != null ? oRecep_sample.Idrecep_sample : 0;
                    int idprice_version = oPrice_version != null ? oPrice_version.Idprice_version : 0;

                    Limpiar_Campos();

                    if (typeModuleOpen == typeModule.RegisterReception)
                    {
                        oRecep_sample = new CRecep_sampleFactory().GetByPrimaryKey(new CRecep_sampleKeys(idrecep_sample));
                    }

                    loadData = LoadData.MasterSearchRR;

                    Recuperar_Registro();

                    ChangeStatusControls();

                    ComunForm.Send_message(this.Text, TypeMsg.ok, "");

                    return true;
                }
                else
                    return false;
            }
            else
                return false;
        }
Ejemplo n.º 7
0
        private void ucToolStrip1_onFind()
        {
            if (typeModuleOpen == typeModule.RegisterReception)
            {
                ///attributes
                short? p_year = null;
                short? p_idcompany = null;
                DateTime? p_date_begin = null;
                DateTime? p_date_end = null;

                FormMasterSearch fmBusqueda = new FormMasterSearch();
                fmBusqueda.BindGrid(new ModMasterSearch().GetRegReception(p_year, p_idcompany, p_date_begin, p_date_end));

                fmBusqueda.ShowDialog();

                Dictionary<string, string> keys = fmBusqueda.getKeyValues();

                if (keys != null)
                {
                    Limpiar_Campos();

                    ///get recep sample
                    oRecep_sample = faRecep_sample.GetByPrimaryKey(new CRecep_sampleKeys(Convert.ToInt64(keys["Idrecep_sample"])));
                    Recuperar_Registro();
                    loadData = LoadData.MasterSearchRR;
                    thePanelTab1.SelectedIndex = 0;
                    statusRegReception = StatusRegRecep.reg_recep_saved;
                }
            }

            ChangeStatusControls();
        }
Ejemplo n.º 8
0
        bool SaveRegisterReception()
        {
            bool result = false;
            object obj = deHourReception.EditValue;

            try
            {
                #region save head

                if (oRecep_sample == null)
                    oRecep_sample = new CRecep_sample();
                else
                {
                    if (loadData == LoadData.FromRR_ToExtendRR)
                        oRecep_sample.Idrecep_sample = 0;
                }

                CPersonFactory faPerson = new CPersonFactory();
                Reception oReception = new BusinessLayer.Modules.Reception();

                // --- save company
                bool result_company = false;

                CCompany oCompany = new CCompany();

                if (cbCompany.EditValue != null)
                {
                    CCorr_modulesFactory faCorr_modules = new CCorr_modulesFactory();
                    CCompanyFactory faCompany = new CCompanyFactory();

                    oCompany.Idcompany = Convert.ToInt16(cbCompany.EditValue);
                    //oCompany.Cod_company = faCorr_modules.GetCorrModule(Comun.Formulario.fmEmpresa.ToString());
                    oCompany.Ruc = tbClientRuc.Text;
                    oCompany.Business_name = cbCompany.Text;
                    oCompany.Domicile = tbClientDomicile.Text;
                    oCompany.Type_company = 'C'; // --- client
                    oCompany.Phone_client = tbClientPhone.Text;

                    if (!(result_company = faCompany.Update(oCompany)))
                        result_company = faCompany.Insert(oCompany);
                }

                // --- save head
                if (!result_company)
                {
                    ComunForm.Send_message(this.Text, TypeMsg.error, "Error al guardar cliente, no se pudo completar la operación.");
                    return false;
                }

                bool result_recep_sample = false;

                oReception.GetNewCodReception();

                oRecep_sample.Cod_recep_sample = oReception.GetFormatCodReception();
                oRecep_sample.Idcompany = oCompany.Idcompany;
                oRecep_sample.Date_reception = deReception.DateTime;

                DateTime Hour_reception = Convert.ToDateTime(deHourReception.EditValue);

                oRecep_sample.Date_reception = new DateTime(
                    deReception.DateTime.Year, deReception.DateTime.Month, deReception.DateTime.Day,
                    Hour_reception.Hour, Hour_reception.Minute, Hour_reception.Second);

                DateTime Hour_result = Convert.ToDateTime(deHourResult.EditValue);

                oRecep_sample.Date_result = new DateTime(
                    deResult.DateTime.Year, deResult.DateTime.Month, deResult.DateTime.Day,
                    Hour_result.Hour, Hour_result.Minute, Hour_result.Second);

                oRecep_sample.Cod_type_sample = cbTypeSample.EditValue.ToString();
                oRecep_sample.Total_amount = Convert.ToDecimal(tbSubTotalAmount.Text);
                oRecep_sample.Total_igv = Convert.ToDecimal(tbTotalIgv.Text);
                oRecep_sample.Total_amount_igv = Convert.ToDecimal(tbTotalAmount.Text);
                oRecep_sample.Amortization = Convert.ToDecimal(tbAmortization.Text);
                oRecep_sample.Flag_isprice = false;
                //oRecep_sample.Discount = ckDiscount.Checked == true ? tbDiscount.Value : 0;

                if (oRecep_sample.Idrecep_sample == 0)
                {
                    oRecep_sample.Usernew = Comun.GetUser();
                    oRecep_sample.Datenew = Comun.GetDate();
                }
                oRecep_sample.Useredit = Comun.GetUser();
                oRecep_sample.Dateedit = Comun.GetDate();

                if (!(result_recep_sample = faRecep_sample.Update(oRecep_sample)))
                    result_recep_sample = faRecep_sample.Insert(oRecep_sample);

                if (!result_recep_sample)
                {
                    ComunForm.Send_message(this.Text, TypeMsg.error, "Error al guardar datos en recepción, no se pudo completar la operación.");
                    return false;
                }

                #endregion

                #region update price

                if (result_recep_sample && oPrice_version != null && oPrice_version.Idprice_version > 0)
                {
                    oPrice_version.Status_price = 4;
                    faPrice_version.Update(oPrice_version);
                }

                #endregion

                #region save detail

                // --- contacts and detail
                if (result_recep_sample)
                {
                    // --- save contacts
                    CPerson oContact = new CPerson();
                    CRecep_company_person oRecep_company_person = new CRecep_company_person();
                    CRecep_company_personFactory faRecep_company_person = new CRecep_company_personFactory();

                    // --- delete all
                    tbCod_recep_sample.Text = oReception.GetFormatCodReception();

                    oReception.SetDisabledContact(oRecep_sample.Idrecep_sample);

                    for (int i = 0; i < gvContact.RowCount; i++)
                    {
                        oContact.Idperson = Convert.ToInt16(gvContact.GetRowCellValue(i, gcCon_Idperson));
                        oContact.Phone = gvContact.GetRowCellValue(i, gcCon_Phone).ToString();
                        oContact.Cellphone = gvContact.GetRowCellValue(i, gcCon_Cellphone).ToString();
                        oContact.Mail = gvContact.GetRowCellValue(i, gcCon_Mail).ToString();
                        oContact.Allname = gvContact.GetRowCellValue(i, gcCon_Allname).ToString();

                        bool result_contact = false;
                        if (!(result_contact = faPerson.Update(oContact)))
                            result_contact = faPerson.Insert(oContact);

                        if (result_contact)
                        {
                            oRecep_company_person = new CRecep_company_person();

                            oRecep_company_person.Idrecep_company_person = 0;
                            oRecep_company_person.Idcompany = oCompany.Idcompany;
                            oRecep_company_person.Idrecep_sample = oRecep_sample.Idrecep_sample;
                            oRecep_company_person.Idperson = oContact.Idperson;
                            oRecep_company_person.Person_type = Convert.ToInt16(gvContact.GetRowCellValue(i, gcCon_Person_type));
                            oRecep_company_person.Enabled_show = true;

                            if (!faRecep_company_person.Update(oRecep_company_person))
                                faRecep_company_person.Insert(oRecep_company_person);
                        }
                    }

                    // --- save dispatch
                    CRecep_sample_dispatchFactory faRecep_sample_dispatch = new CRecep_sample_dispatchFactory();
                    CRecep_sample_dispatch oRecep_sample_dispatch = new CRecep_sample_dispatch();
                    oRecep_sample_dispatch.Idrecep_sample = oRecep_sample.Idrecep_sample;
                    // --- person
                    if (ckDispatchPerson.Checked)
                        oRecep_sample_dispatch.Dispatch_person = 1;
                    else
                        oRecep_sample_dispatch.Dispatch_person = 0;
                    // --- curier
                    if (ckDispatchCurier.Checked)
                        oRecep_sample_dispatch.Dispatch_curier = 1;
                    else
                        oRecep_sample_dispatch.Dispatch_curier = 0;
                    // --- transport
                    if (ckDispatchTransport.Checked)
                        oRecep_sample_dispatch.Dispatch_transport = 1;
                    else
                        oRecep_sample_dispatch.Dispatch_transport = 0;
                    // --- fax
                    if (ckDispatchFax.Checked)
                        oRecep_sample_dispatch.Dispatch_fax = 1;
                    else
                        oRecep_sample_dispatch.Dispatch_fax = 0;
                    // --- save
                    if (!faRecep_sample_dispatch.Update(oRecep_sample_dispatch))
                        faRecep_sample_dispatch.Insert(oRecep_sample_dispatch);

                    // ---------------------------------------------------------------------------
                    // --- save detail -----------------------------------------------------------
                    // ---------------------------------------------------------------------------
                    CRecep_sample_detail oRecep_sample_detail = new CRecep_sample_detail();
                    CRecep_sample_detailFactory faRecep_sample_detail = new CRecep_sample_detailFactory();

                    CRecep_elem oRecep_elem = new CRecep_elem();
                    CRecep_elemFactory faRecep_elem = new CRecep_elemFactory();

                    CRecep_sample_detail_elem oRecep_sample_detail_elem = new CRecep_sample_detail_elem();
                    CRecep_sample_detail_elemFactory faRecep_sample_detail_elem = new CRecep_sample_detail_elemFactory();

                    CCorrelative oCorrelative = new CCorrelativeFactory().GetByPrimaryKey(new CCorrelativeKeys(oRecep_sample.Cod_type_sample));

                    if (oRecep_sample.Idrecep_sample > 0)
                    {
                        int i = 0;
                        while (i < gvReception.RowCount)
                        {
                            oRecep_sample_detail = new CRecep_sample_detail();
                            oRecep_sample_detail.Idrecep_sample = oRecep_sample.Idrecep_sample;
                            //if (gvReception.GetRowCellValue(i, gcRec_idrecep_sample_detail) != DBNull.Value)
                                //oRecep_sample_detail.Idrecep_sample_detail = Convert.ToInt64(gvReception.GetRowCellValue(i, gcRec_idrecep_sample_detail));
                            oRecep_sample_detail.Idrecep_sample_detail = 0;
                            oRecep_sample_detail.Order_sample = Convert.ToInt16(gvReception.GetRowCellValue(i, gcRec_OrderSample));
                            oRecep_sample_detail.Name_sample = gvReception.GetRowCellValue(i, gcRec_NameSample).ToString();
                            oRecep_sample_detail.Procedence = gvReception.GetRowCellValue(i, gcRec_Procedence).ToString();
                            oRecep_sample_detail.Cod_des_sample = gvReception.GetRowCellValue(i, gcRec_Description).ToString();
                            oRecep_sample_detail.Cod_type_sample = gvReception.GetRowCellValue(i, gcRec_Type_Sample).ToString();
                            oRecep_sample_detail.Cod_sample = gvReception.GetRowCellValue(i, gcRec_Code).ToString();
                            oRecep_sample_detail.Amount_weight = Convert.ToDecimal(gvReception.GetRowCellValue(i, gcRec_CantKg));
                            oRecep_sample_detail.Cost_sample = Convert.ToDecimal(gvReception.GetRowCellValue(i, gcRec_Cost));
                            oRecep_sample_detail.Flag_envelope_sealed = Convert.ToBoolean(gvReception.GetRowCellValue(i, gcRec_Flag_envelope_sealed));
                            oRecep_sample_detail.Flag_reject = Convert.ToBoolean(gvReception.GetRowCellValue(i, gcRec_Reject));
                            oRecep_sample_detail.Flag_counter_sample = Convert.ToInt16(gvReception.GetRowCellValue(i, gcRec_Counter_Sample));
                            oRecep_sample_detail.Analisys_time = Convert.ToInt16(gvReception.GetRowCellValue(i, gcRec_Days));

                            bool result_detail_elem = false;

                            bool result_recep_sample_detail = false;

                            if (!(result_recep_sample_detail = faRecep_sample_detail.Update(oRecep_sample_detail)))
                                result_recep_sample_detail = faRecep_sample_detail.Insert(oRecep_sample_detail);

                            if (result_recep_sample_detail)
                            {
                                if (FlagRegRecepCopy)
                                {
                                    oRecep_sample_detail.Cod_interno = Convert.ToInt64(gvReception.GetRowCellValue(i, gcRec_Cod_interno));
                                    oRecep_sample_detail.Cod_sample = gvReception.GetRowCellValue(i, gcRec_Code).ToString();
                                    oRecep_sample_detail.Flag_control_sample = false;
                                }
                                else
                                {
                                    // assign correlative code
                                    long Cod_interno = oReception.GetNewCodInternoSample(gvReception.GetRowCellValue(i, gcRec_Type_Sample).ToString());
                                    string Format_cod_interno = oReception.GetFormatCodInternoSample(gvReception.GetRowCellValue(i, gcRec_Type_Sample).ToString());

                                    oRecep_sample_detail.Cod_interno = Cod_interno;
                                    oRecep_sample_detail.Cod_sample = Format_cod_interno;
                                    oRecep_sample_detail.Flag_control_sample = false;
                                }

                                faRecep_sample_detail.Update(oRecep_sample_detail);

                                #region save element cell repetition

                                CRecep_sample_detail oRecep_sample_aux = faRecep_sample_detail.GetByPrimaryKey(new CRecep_sample_detailKeys(oRecep_sample_detail.Idrecep_sample_detail));
                                CSettings oSettings = new CSettings();
                                bool HasHumidityAnalysis = false;
                                bool Has60GradesElement = false;

                                // --- retrieve code sample and assign
                                if (!Convert.ToBoolean(oRecep_sample_detail.Flag_control_sample))
                                    gvReception.SetRowCellValue(i, gcRec_Code, oRecep_sample_aux.Cod_sample);

                                // --- save element cell
                                foreach (KeyValuePair<DevExpress.XtraGrid.Columns.GridColumn, bool> kvp in DicShowColumns)
                                {
                                    if (kvp.Value)
                                    {
                                        bool value_check = Convert.ToBoolean(gvReception.GetRowCellValue(i, kvp.Key));
                                        bool flag_control_sample = Convert.ToBoolean(oRecep_sample_detail.Flag_control_sample);

                                        if ((!flag_control_sample && value_check)
                                            || flag_control_sample)
                                        {
                                            oRecep_sample_detail_elem = new CRecep_sample_detail_elem();

                                            CTagInfoMethod tagMethod = (CTagInfoMethod)kvp.Key.Tag;
                                            oRecep_sample_detail_elem.Idelement = tagMethod.IDElement;
                                            oRecep_sample_detail_elem.Idrecep_sample = oRecep_sample.Idrecep_sample;
                                            oRecep_sample_detail_elem.Idrecep_sample_detail = oRecep_sample_detail.Idrecep_sample_detail;
                                            oRecep_sample_detail_elem.Idtemplate_method = tagMethod.IDTemplate_method;
                                            oRecep_sample_detail_elem.Idcompany = oRecep_sample.Idcompany;
                                            oRecep_sample_detail_elem.Idunit = tagMethod.IDMeasurement_Unit;
                                            oRecep_sample_detail_elem.Cost_method = tagMethod.Cost_Method;

                                            if (!(result_detail_elem = faRecep_sample_detail_elem.Update(oRecep_sample_detail_elem)))
                                                result_detail_elem = faRecep_sample_detail_elem.Insert(oRecep_sample_detail_elem);

                                            if (result_detail_elem)
                                            {
                                                // crear bandejas
                                                CBatchManager oBatchManager = new CBatchManager();
                                                oBatchManager.CallSaveSampleBatch(
                                                    Convert.ToInt32(oRecep_sample_detail_elem.Idtemplate_method),
                                                    Convert.ToInt64(oRecep_sample_detail_elem.Idrecep_sample),
                                                    Convert.ToInt64(oRecep_sample_detail_elem.Idrecep_sample_detail),
                                                    oRecep_sample_detail_elem.Idrecep_sample_detail_elem,
                                                    Convert.ToInt64(oRecep_sample_detail.Cod_interno),
                                                    oRecep_sample_detail.Cod_sample,
                                                    Comun.GetUser(),
                                                    oCorrelative);

                                                // enviar a preparación de muestras

                                            }

                                            //verificar si tiene análisis por humedad
                                            if (oSettings.GetIdHumidityAnalysis().Contains(tagMethod.IDElement.ToString()))
                                                HasHumidityAnalysis = true;

                                            //verificar si tiene que elementos para ser analizados a 60°
                                            if (oSettings.GetIDElements60Grades().Contains(tagMethod.IDElement.ToString()))
                                                Has60GradesElement = true;
                                        }
                                    }
                                }
                                #endregion

                                #region save sample preparation

                                CPrep_samples oPrep_samples = new CPrep_samples();
                                oPrep_samples.Idrecep_sample_detail = oRecep_sample_detail.Idrecep_sample_detail;
                                oPrep_samples.Flag_counter_sample = oRecep_sample_detail.Flag_counter_sample;
                                oPrep_samples.Flag_reject = oRecep_sample_detail.Flag_reject;
                                oPrep_samples.Flag_humidity_analysis = HasHumidityAnalysis;
                                oPrep_samples.Flag_60celsius = Has60GradesElement;
                                oPrep_samples.Date_creation = Comun.GetDate();
                                oPrep_samples.Moisture_reject = false;
                                oPrep_samples.Final_moisture = 0;
                                oPrep_samples.Final_reject = 0;
                                oPrep_samples.Final_sample_prepared = 0;
                                oPrep_samples.Final_weight_gross = 0;
                                oPrep_samples.Output_flag_sample = false;
                                oPrep_samples.Output_flag_cs = false;
                                oPrep_samples.Output_flag_re = false;

                                CPrep_samplesFactory faPrep_samples = new CPrep_samplesFactory();
                                if (!faPrep_samples.Update(oPrep_samples))
                                    faPrep_samples.Insert(oPrep_samples);

                                #endregion
                            }

                            if (!Convert.ToBoolean(oRecep_sample_detail.Flag_control_sample))
                                i++;
                        }
                    }

                    #region save tag infor method

                    // --- save tag info method (mr or blk)
                    foreach (KeyValuePair<DevExpress.XtraGrid.Columns.GridColumn, bool> kvp in DicShowColumns)
                    {
                        if (kvp.Value)
                        {
                            CTagInfoMethod tagMethod = (CTagInfoMethod)kvp.Key.Tag;
                            oRecep_elem = new CRecep_elem();
                            oRecep_elem.Idelement = tagMethod.IDElement;
                            oRecep_elem.Idrecep_sample = oRecep_sample.Idrecep_sample;
                            oRecep_elem.Idtemplate_method = tagMethod.IDTemplate_method;
                            oRecep_elem.Name_unit = tagMethod.Name_Measurement_Unit;
                            oRecep_elem.Idunit = tagMethod.IDMeasurement_Unit;
                            oRecep_elem.Percent_repetition = tagMethod.Percent_repetition;

                            if (!faRecep_elem.Update(oRecep_elem))
                                faRecep_elem.Insert(oRecep_elem);
                        }
                    }

                    #endregion
                }

                #endregion

                result = true;
            }
            catch (Exception ex)
            {
                Comun.Save_log(ex.Message);
                if (ex.InnerException != null)
                    Comun.Save_log(ex.InnerException.ToString());
                return false;
            }
            return result;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// inicializa un nuevo registro de recepción a partir de otro
        /// </summary>
        /// <param name="pRecep_sample"></param>
        public FormReception(CRecep_sample pRecep_sample, LoadData generic)
        {
            InitializeComponent();

            oRecep_sample = pRecep_sample;

            loadData = generic;

            // --- crear a un nuevo registro de recepción
            if (loadData == LoadData.FromRR_ToExtendRR)
                FlagRegRecepCopy = true;

            typeModuleOpen = typeModule.RegisterReception;

            Init();

            Recuperar_Registro();

            ChangeStatusControls();

            statusRegReception = StatusRegRecep.reg_recep_saved;
        }
Ejemplo n.º 10
0
        void OpenFormMasterSearch(typeModule tm)
        {
            if (tm == typeModule.RegisterReception)
            {
                ///attributes
                short? p_year = null;
                short? p_idcompany = null;
                DateTime? p_date_begin = null;
                DateTime? p_date_end = null;

                FormMasterSearch fmBusqueda = new FormMasterSearch();
                fmBusqueda.BindGrid(new ModMasterSearch().GetRegReception(p_year, p_idcompany, p_date_begin, p_date_end));

                fmBusqueda.ShowDialog();

                Dictionary<string, string> keys = fmBusqueda.getKeyValues();

                if (keys != null)
                {
                    ///get recep sample
                    oRecep_sample = faRecep_sample.GetByPrimaryKey(new CRecep_sampleKeys(Convert.ToInt64(keys["Idrecep_sample"])));
                    oPrice_version = faPrice_version.GetByPrimaryKey(new CPrice_versionKeys(Convert.ToInt32(keys["Idprice_version"])));
                    Limpiar_Campos();
                    Recuperar_Registro();
                    thePanelTab1.SelectedIndex = 0;
                    statusRegReception = StatusRegRecep.reg_recep_saved;
                }
            }
        }