Beispiel #1
0
        private async void dgvSales_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (this.dgvSales.Rows[e.RowIndex].Cells["DetailSale"].Selected)
                {
                    this.PaintRowAndUnpaintLastSelectedRow(e.RowIndex);

                    long idSale = (long)this.dgvSales.Rows[e.RowIndex].Cells["idSale"].Value;
                    this.dgvDetailsSale.DataSource = await DetailSaleService.ListDetailSaleLikeCartItemByIdSale(idSale);
                }
                else if (this.dgvSales.Rows[e.RowIndex].Cells["PDFView"].Selected)
                {
                    this.PaintRowAndUnpaintLastSelectedRow(e.RowIndex);

                    long idSale = (long)this.dgvSales.Rows[e.RowIndex].Cells["idSale"].Value;
                    SaleService.ExportInPDFDetailSaleLikeCartItemByIdSale(idSale);
                }
                else if (this.dgvSales.Rows[e.RowIndex].Cells["cancelSale"].Selected)
                {
                    this.PaintRowAndUnpaintLastSelectedRow(e.RowIndex);

                    DialogResult    result          = new DialogResult();
                    FormInformation formInformation = new FormInformation("¿ESTAS SEGURO DE ANULAR LA VENTA?");
                    result = formInformation.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        long idSale = (long)this.dgvSales.Rows[e.RowIndex].Cells["idSale"].Value;
                        if (await SaleService.CancelSaleByIdSale(idSale))
                        {
                            FormSuccess.ConfirmationForm("ANULADO");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private async void btnRegisterSale_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtNameClient.Text == string.Empty)
                {
                    throw new ArgumentNullException("Debe ingresar el nombre del cliente.");
                }
                if (this.cartDetailSale.getCount() == 0)
                {
                    throw new ArgumentException("Debe registrar como minimo 1 producto a vender para realizar la venta");
                }

                Sale mySale = new Sale
                {
                    nameClient     = txtNameClient.Text,
                    detailSaleList = this.cartDetailSale.ToDetailSaleList(),
                    total          = this.cartDetailSale.total
                };
                Sale resultSale = await SaleService.RegisterSale(mySale);

                DialogResult            result = new DialogResult();
                FormSuccessRegisterSale formSuccessRegisterSale = new FormSuccessRegisterSale("REGISTRADO");
                result = formSuccessRegisterSale.ShowDialog(this);

                if (result == DialogResult.Yes)
                {
                    SaleService.ExportInPDFDetailSaleLikeCartItemByIdSale(resultSale.idSale);
                }

                this.ResetRegisterConfiguration();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }