Ejemplo n.º 1
0
        private void btnCreateOrder_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(@"Desea proceder a crear esta orden?", @"Crear", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                if (IsReadyToSave())
                {
                    try
                    {
                        string sqlForExecute;
                        if (pedidoID.Equals(0))
                        {
                            pedidoID              = DataUtil.GetNewId("pedido");
                            ordenDiaID            = DataUtil.GetOrderByTurn(DataUtil.GetInt(lblTurno.Text));
                            Text                  = Text + @": " + pedidoID;
                            lblOrderDiaNo.Text    = DataUtil.GetString(ordenDiaID);
                            lblOrderDia.Visible   = true;
                            lblOrderDiaNo.Visible = true;

                            string clienteIDValue = "null";
                            if (clienteID != string.Empty)
                            {
                                clienteIDValue = clienteID;
                            }

                            string mesaIDValue = "null";
                            if (mesaID != string.Empty)
                            {
                                mesaIDValue = mesaID;
                            }

                            sqlForExecute = "INSERT INTO pedido (" +
                                            "Pedido_id," +
                                            "Mesa_id," +
                                            "Turno_id," +
                                            "Fecha_Pedido," +
                                            "Atendido_por," +
                                            "Estado," +
                                            "Tipo_venta," +
                                            "Cliente_id," +
                                            "Orden_turno)" +
                                            " VALUES (" +
                                            pedidoID + "," +
                                            "" + mesaIDValue + "," +
                                            "" + lblTurno.Text + "," +
                                            "'" + DateTime.Now + "'," +
                                            "" + radmccbEmpleado.EditorControl.Rows[radmccbEmpleado.SelectedIndex].Cells["Codigo_empleado"].Value + "," +
                                            "'A'," +
                                            "'" + tipoVenta + "'," +
                                            "" + clienteIDValue + "," +
                                            "" + ordenDiaID + "" +
                                            ")";

                            DataUtil.UpdateThrow(sqlForExecute);
                        }

                        foreach (DataGridViewRow row in dgwCuenta.Rows)
                        {
                            string descuentoValue = DataUtil.GetString(row.Cells[gridDescuento].Value);
                            if (descuentoValue.Equals(string.Empty))
                            {
                                descuentoValue = "null";
                            }

                            sqlForExecute = "INSERT INTO pedido_detalle (" +
                                            "Pedido_detalle_id," +
                                            "Pedido_id," +
                                            "Linea," +
                                            "Codigo_Producto," +
                                            "Descripcion_Producto," +
                                            "Descuento," +
                                            "Cantidad," +
                                            "Impreso)" +
                                            " VALUES (" +
                                            DataUtil.GetNewId("pedido_detalle") + "," +
                                            pedidoID + "," +
                                            "'" + DataUtil.GetString(row.Cells[gridLineaNumero].Value) + "'," +
                                            "" + DataUtil.GetString(row.Cells[gridProdCodigo].Value) + "," +
                                            "'" + DataUtil.GetString(row.Cells[gridProdDescripcion].Value).Replace("'", "''") + "'," +
                                            "" + descuentoValue + "," +
                                            "'" + DataUtil.GetString(row.Cells[gridCantidad].Value) + "'," +
                                            "0" +
                                            ")";
                            DataUtil.UpdateThrow(sqlForExecute);
                        }

                        if (mesaID != string.Empty)
                        {
                            sqlForExecute = "UPDATE mesa SET " +
                                            " Mesa_estado = 'OCUPADA'," +
                                            " Pedido_id = " + pedidoID + "" +
                                            " WHERE Mesa_id = " + mesaID;
                            DataUtil.UpdateThrow(sqlForExecute);
                        }

                        sqlForExecute = "UPDATE pedido SET " +
                                        "  Last_Line = " + lineGrid + "" +
                                        ", Fecha_actualizacion = '" + DateTime.Now + "'" +
                                        ", Actualizado_por = '" + radmccbEmpleado.EditorControl.Rows[radmccbEmpleado.SelectedIndex].Cells["Codigo_empleado"].Value + "'" +
                                        " WHERE Pedido_id = " + pedidoID;
                        DataUtil.UpdateThrow(sqlForExecute);


                        PrintDocuments(pedidoID, 0);
                        btnReprint.Visible     = true;
                        btnCreateOrder.Visible = false;
                        MessageBox.Show(@"Orden agregada correctamente.", @"Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        btnNewOrder.Visible     = true;
                        radmccbEmpleado.Enabled = false;
                        ShowButtonsOrder(true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(@"Error en Grabar: " + ex.Message);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void SaveAccount(DataGridView dgvMain, int lineGrid)
        {
            int pedidoID   = 0;
            int ordenDiaID = 0;

            string sqlForExecute = string.Empty;

            try
            {
                if (pedidoID.Equals(0))
                {
                    pedidoID   = DataUtil.GetNewId("pedido");
                    ordenDiaID = DataUtil.GetOrderByTurn(DataUtil.GetInt(lblTurno.Text));

                    string clienteIDValue = "null";
                    if (clienteIDView != string.Empty)
                    {
                        clienteIDValue = clienteIDView;
                    }

                    string mesaIDValue = "null";
                    if (mesaIDView != string.Empty)
                    {
                        mesaIDValue = mesaIDView;
                    }

                    sqlForExecute = "INSERT INTO pedido (" +
                                    "Pedido_id," +
                                    "Mesa_id," +
                                    "Turno_id," +
                                    "Fecha_Pedido," +
                                    "Atendido_por," +
                                    "Estado," +
                                    "Tipo_venta," +
                                    "Cliente_id," +
                                    "Pedido_origen_id," +
                                    "Orden_turno)" +
                                    " VALUES (" +
                                    pedidoID + "," +
                                    "" + mesaIDValue + "," +
                                    "" + lblTurno.Text + "," +
                                    "'" + DateTime.Now + "'," +
                                    "" + AppConstant.EmployeeInfo.Codigo + "," +
                                    "'A'," +
                                    "'" + tipoVentaView + "'," +
                                    "" + clienteIDValue + "," +
                                    "" + pedidoIDView + "," +
                                    "" + ordenDiaID + "" +
                                    ")";

                    DataUtil.UpdateThrow(sqlForExecute);
                }

                foreach (DataGridViewRow row in dgvMain.Rows)
                {
                    string descuentoValue = DataUtil.GetString(row.Cells[4].Value);
                    if (descuentoValue.Equals(string.Empty))
                    {
                        descuentoValue = "null";
                    }

                    sqlForExecute = "INSERT INTO pedido_detalle (" +
                                    "Pedido_detalle_id," +
                                    "Pedido_id," +
                                    "Linea," +
                                    "Codigo_Producto," +
                                    "Descripcion_Producto," +
                                    "Descuento," +
                                    "Cantidad," +
                                    "Impreso)" +
                                    " VALUES (" +
                                    DataUtil.GetNewId("pedido_detalle") + "," +
                                    pedidoID + "," +
                                    "'" + DataUtil.GetString(row.Cells[0].Value) + "'," +
                                    "" + DataUtil.GetString(row.Cells[1].Value) + "," +
                                    "'" + DataUtil.GetString(row.Cells[3].Value).Replace("'", "''") + "'," +
                                    "" + descuentoValue + "," +
                                    "'" + DataUtil.GetString(row.Cells[2].Value) + "'," +
                                    "0" +
                                    ")";
                    DataUtil.UpdateThrow(sqlForExecute);
                }

                sqlForExecute = "UPDATE pedido SET " +
                                "Last_Line = " + lineGrid + "" +
                                ", Fecha_actualizacion = '" + DateTime.Now + "'" +
                                ", Actualizado_por = '" + AppConstant.EmployeeInfo.Codigo + "'" +
                                " WHERE Pedido_id = " + pedidoID;
                DataUtil.UpdateThrow(sqlForExecute);

                ordenesCreadas++;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en Grabar: " + ex.Message);
            }
        }