Example #1
0
        void InitDataControls()
        {
            deDateCreation.DateTime = Comun.GetDate();
            tbNumDaysValid.Value    = new CSettings().GetNumDaysPriceDefault();

            // --- init company
            cbCompany.Properties.DataSource    = new CCompanyFactory().GetAll();
            cbCompany.Properties.DisplayMember = "Business_name";
            cbCompany.Properties.ValueMember   = "Idcompany";

            // --- init type sample combo
            CType_sampleFactory faType_Sample = new CType_sampleFactory();

            cbTypeSample.Properties.DataSource    = faType_Sample.GetAll();
            cbTypeSample.Properties.ValueMember   = "Cod_type_sample";
            cbTypeSample.Properties.DisplayMember = "Name_type_sample";

            Reception oReception = new Reception();

            // --- init type person
            repPerson_type.DataSource    = oReception.GetLstPersonType();
            repPerson_type.DisplayMember = "Name";
            repPerson_type.ValueMember   = "Id";

            // --- init methods
            gcPrice.DataSource = new BindingList <PriceMethod>(new ModPrice().GetPriceMethod(null));

            // --- init plantillas
            CMemo_templateFactory faMemo_template = new CMemo_templateFactory();

            gcParagraphHistoryIni.DataSource = faMemo_template.GetAll().Where(c => c.Memo_type == 1).ToList();

            gcParagraphHistoryEnd.DataSource = faMemo_template.GetAll().Where(c => c.Memo_type == 2).ToList();

            // --- init adjuntos
            List <Anexos> list = new ModPrice().GetLstAnexos(null);

            gcAnexos.DataSource = new BindingList <Anexos>(list);
        }
Example #2
0
        protected override void Recuperar_Registro()
        {
            if (oPrice != null && oPrice_version != null)
            {
                tabHead.Text             = oPrice.Cod_price;
                tbCodPrice.Text          = oPrice.Cod_price;
                tbNumVersion.Text        = oPrice_version.Num_version.ToString();
                cbTypeSample.EditValue   = oPrice_version.Cod_type_sample;
                cbCompany.EditValue      = oPrice_version.Idcompany;
                deDateCreation.EditValue = oPrice_version.Date_creation;
                tbNumDaysValid.Value     = Convert.ToInt32(oPrice_version.Num_days_valid);
                tbObservation.Text       = oPrice_version.Observation;

                // --- person
                if (oPrice.Dispatch_person > 0)
                {
                    ckDispatchPerson.Checked = true;
                }
                else
                {
                    ckDispatchPerson.Checked = false;
                }
                // --- curier
                if (oPrice.Dispatch_curier > 0)
                {
                    ckDispatchCurier.Checked = true;
                }
                else
                {
                    ckDispatchCurier.Checked = false;
                }
                // --- transport
                if (oPrice.Dispatch_transport > 0)
                {
                    ckDispatchTransport.Checked = true;
                }
                else
                {
                    ckDispatchTransport.Checked = false;
                }
                // --- fax
                if (oPrice.Dispatch_fax > 0)
                {
                    ckDispatchFax.Checked = true;
                }
                else
                {
                    ckDispatchFax.Checked = false;
                }

                // --- get contacts
                gcContact.DataSource = new BindingList <CContact_price>(new ModPrice().GetLstContactsByPrice(oPrice.Idprice, oPrice_version.Idprice_version));

                // --- recuperando métodos
                List <PriceMethod> myLstPriceMethod = new ModPrice().GetPriceMethod(oPrice_version);

                gcPrice.DataSource = new BindingList <PriceMethod>(myLstPriceMethod);

                // --- recuperando parrafos
                var lstmemo =
                    (from m in new CMemo_priceFactory().GetAll()
                     where m.Idprice_version == oPrice_version.Idprice_version
                     select new
                {
                    m.Paragraph,
                    m.Memo_type
                }).ToList();

                foreach (var item in lstmemo)
                {
                    if (item.Memo_type == 1)
                    {
                        richTextIni.RichTextBox.Rtf = item.Paragraph;
                    }
                    else if (item.Memo_type == 2)
                    {
                        richTextEnd.RichTextBox.Rtf = item.Paragraph;
                    }
                }

                // --- recuperar memo template
                var lsttemplate_memo = new CMemo_templateFactory().GetAll();

                gcParagraphHistoryIni.DataSource = lsttemplate_memo.Where(c => c.Memo_type == 1).ToList();

                gcParagraphHistoryEnd.DataSource = lsttemplate_memo.Where(c => c.Memo_type == 2).ToList();

                // --- recalcular tamaño de celdas de texto amplio
                gvPrice.OptionsView.RowAutoHeight = true;
                gvPrice.LayoutChanged();

                gvParagraphHistoryIni.OptionsView.RowAutoHeight = true;
                gvParagraphHistoryIni.LayoutChanged();

                gvParagraphHistoryEnd.OptionsView.RowAutoHeight = true;
                gvParagraphHistoryEnd.LayoutChanged();

                // --- recuperar suma totales
                SumTotals();

                // --- recuperar reporte de cotización
                ShowPreviewReport();

                // --- recuperar archivos adjuntos
                gcAnexos.DataSource = new BindingList <Anexos>(new ModPrice().GetLstAnexos(oPrice_version));
            }
            else
            {
                ckDispatchPerson.Checked    = false;
                ckDispatchCurier.Checked    = true;
                ckDispatchTransport.Checked = false;
                ckDispatchFax.Checked       = false;
            }
        }
Example #3
0
        protected override bool Grabar_Registro()
        {
            // --- 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);
                }
            }

            bool result_price = false;

            if (oPrice == null)
            {
                oPrice = new CPrice();
            }

            CPriceFactory faPrice = new CPriceFactory();

            if (!(loadData == LoadData.FromPrice_ToNewVersion))
            {
                oPrice.Cod_price = new ModCorrelatives().GetCorrelative(Comun.Correlative.Price);
            }

            // --- person
            if (ckDispatchPerson.Checked)
            {
                oPrice.Dispatch_person = 1;
            }
            else
            {
                oPrice.Dispatch_person = 0;
            }
            // --- curier
            if (ckDispatchCurier.Checked)
            {
                oPrice.Dispatch_curier = 1;
            }
            else
            {
                oPrice.Dispatch_curier = 0;
            }
            // --- transport
            if (ckDispatchTransport.Checked)
            {
                oPrice.Dispatch_transport = 1;
            }
            else
            {
                oPrice.Dispatch_transport = 0;
            }
            // --- fax
            if (ckDispatchFax.Checked)
            {
                oPrice.Dispatch_fax = 1;
            }
            else
            {
                oPrice.Dispatch_fax = 0;
            }

            if (!(result_price = faPrice.Update(oPrice)))
            {
                result_price = faPrice.Insert(oPrice);
            }

            // --- save contacts
            CPerson                      oContact = new CPerson();
            CPersonFactory               faPerson = new CPersonFactory();
            CPrice_company_person        oPrice_company_person  = new CPrice_company_person();
            CPrice_company_personFactory faPrice_company_person = new CPrice_company_personFactory();

            // --- delete all
            if (result_price)
            {
                oPrice_version = new CPrice_version();
                CPrice_versionFactory faPrice_version = new CPrice_versionFactory();

                oPrice_version.Idprice = oPrice.Idprice;

                oPrice_version.Idcompany = null;
                if (cbCompany.EditValue != null)
                {
                    oPrice_version.Idcompany = Convert.ToInt16(cbCompany.EditValue);
                }

                oPrice_version.Cod_type_sample = cbTypeSample.EditValue.ToString();
                oPrice_version.Num_version     = new ModPrice().GetNextNumVersion(oPrice.Idprice);
                oPrice_version.Date_creation   = deDateCreation.DateTime;
                oPrice_version.Num_days_valid  = Convert.ToInt16(tbNumDaysValid.Value);

                oPrice_version.Observation = tbObservation.Text;

                oPrice_version.Iduser       = Comun.User_system.Iduser;
                oPrice_version.Status_price = 1;

                bool result_price_version = false;
                if (!(result_price_version = faPrice_version.Update(oPrice_version)))
                {
                    result_price_version = faPrice_version.Insert(oPrice_version);
                }

                if (result_price_version)
                {
                    //guardar párrafos iniciales
                    CMemo_price        oMemoPrice;
                    CMemo_priceFactory faMemo_price = new CMemo_priceFactory();

                    //guardando el parrafo inicial
                    oMemoPrice = new CMemo_price();
                    oMemoPrice.Idprice_version = oPrice_version.Idprice_version;
                    oMemoPrice.Paragraph       = richTextIni.RichTextBox.Rtf;
                    oMemoPrice.Memo_type       = 1;
                    faMemo_price.Insert(oMemoPrice);

                    //guardando el parrafo final
                    oMemoPrice = new CMemo_price();
                    oMemoPrice.Idprice_version = oPrice_version.Idprice_version;
                    oMemoPrice.Paragraph       = richTextEnd.RichTextBox.Rtf;
                    oMemoPrice.Memo_type       = 2;
                    faMemo_price.Insert(oMemoPrice);

                    if (ckSaveHistoryIni.Checked)
                    {
                        CMemo_template        oMemo_template  = new CMemo_template();
                        CMemo_templateFactory faMemo_template = new CMemo_templateFactory();

                        oMemo_template.Paragraph     = richTextIni.RichTextBox.Text;
                        oMemo_template.Paragraph_rtf = richTextIni.RichTextBox.Rtf.ToString();
                        oMemo_template.Memo_type     = 1;
                        faMemo_template.Insert(oMemo_template);
                    }

                    //guardar párrafos finales
                    if (ckSaveHistoryEnd.Checked)
                    {
                        CMemo_template        oMemo_template  = new CMemo_template();
                        CMemo_templateFactory faMemo_template = new CMemo_templateFactory();

                        oMemo_template.Paragraph_rtf = richTextEnd.RichTextBox.Rtf;
                        oMemo_template.Paragraph     = richTextEnd.RichTextBox.Text.ToString();
                        oMemo_template.Memo_type     = 2;
                        faMemo_template.Insert(oMemo_template);
                    }
                }

                if (result_price)
                {
                    CCompany_person        oCompany_person  = new CCompany_person();
                    CCompany_personFactory faCompany_person = new CCompany_personFactory();

                    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)
                        {
                            oPrice_company_person = new CPrice_company_person();

                            oPrice_company_person.Idprice_company_person = 0;
                            oPrice_company_person.Idcompany       = oCompany.Idcompany;
                            oPrice_company_person.Idprice         = oPrice.Idprice;
                            oPrice_company_person.Idperson        = oContact.Idperson;
                            oPrice_company_person.Idprice_version = oPrice_version.Idprice_version;
                            oPrice_company_person.Person_type     = Convert.ToInt16(gvContact.GetRowCellValue(i, gcCon_Person_type));

                            if (!faPrice_company_person.Update(oPrice_company_person))
                            {
                                faPrice_company_person.Insert(oPrice_company_person);
                            }
                        }

                        // --- save history company person
                        if (!faCompany_person.GetAll().Exists(c => c.Idcompany == oCompany.Idcompany && c.Idperson == oContact.Idperson))
                        {
                            oCompany_person           = new CCompany_person();
                            oCompany_person.Idcompany = oCompany.Idcompany;
                            oCompany_person.Idperson  = oContact.Idperson;

                            if (!faCompany_person.Update(oCompany_person))
                            {
                                faCompany_person.Insert(oCompany_person);
                            }
                        }
                    }
                }

                if (result_price_version)
                {
                    // guardar detalle
                    CPrice_version_detail        oPrice_version_detail  = new CPrice_version_detail();
                    CPrice_version_detailFactory faPrice_version_detail = new CPrice_version_detailFactory();

                    for (int i = 0; i < gvPrice.RowCount; i++)
                    {
                        oPrice_version_detail = new CPrice_version_detail();
                        oPrice_version_detail.Idprice_version   = oPrice_version.Idprice_version;
                        oPrice_version_detail.Idtemplate_method = Convert.ToInt32(gvPrice.GetRowCellValue(i, gcolItem_Idtemplate_method));
                        oPrice_version_detail.Num_item          = Convert.ToInt32(gvPrice.GetRowCellValue(i, gcolItem_Num_item));
                        oPrice_version_detail.Amount_item       = Convert.ToInt32(gvPrice.GetRowCellValue(i, gcolItem_Amount_item));
                        oPrice_version_detail.Sale_price        = Convert.ToDecimal(gvPrice.GetRowCellValue(i, gcolItem_Sale_price));
                        oPrice_version_detail.Unit_price        = Convert.ToDecimal(gvPrice.GetRowCellValue(i, gcolItem_Unit_price));

                        if (!faPrice_version_detail.Update(oPrice_version_detail))
                        {
                            faPrice_version_detail.Insert(oPrice_version_detail);
                        }
                    }
                }

                if (result_price_version)
                {
                    if (gvAnexos.RowCount > 0)
                    {
                        // guardar adjuntos
                        ListCopy lstCopySave = new ListCopy();

                        List <Anexos> lstAnexos = (gcAnexos.DataSource as BindingList <Anexos>).ToList();

                        if (lstAnexos != null && lstAnexos.Count > 0)
                        {
                            foreach (Anexos item in lstAnexos)
                            {
                                if (item.Source_filename.Trim().Length > 0)
                                {
                                    string destiny_directory = oSettings.GetPathAttachPrice();

                                    lstCopySave.Add(
                                        new CItemCopy()
                                    {
                                        Filename          = item.Filename,
                                        Source_file       = item.Source_filename,
                                        Destiny_directory = destiny_directory
                                    });
                                }
                            }

                            lstCopySave.Save(oPrice, oPrice_version);
                        }
                    }
                }
            }

            return(true);
        }