コード例 #1
0
        private void btnCrear_Click(object sender, EventArgs e)
        {
            if (btnCrear.Text == "Crear")
            {
                if (string.IsNullOrEmpty(txtMoneda.Text))
                {
                    this.SetMensaje("Campo MONEDA obligatorio", 5000, Color.Red, Color.White);
                    return;
                }
                #region Crear
                try
                {
                    Cursor.Current = Cursors.WaitCursor;

                    SDK_SAP.Clases.Document document = new SDK_SAP.Clases.Document();
                    document.DocType     = "dDocument_Items";
                    document.Comments    = txtComments.Text;
                    document.CardCode    = txtCardCode.Text;
                    document.DocDate     = dtpDocDate.Value;
                    document.Series      = 13;
                    document.DocCurrency = txtMoneda.Text;
                    document.DocRate     = txtMoneda.Text == "USD" ? Convert.ToDouble(txtTC.Text) : (double)1;

                    foreach (var item in dgvDatos.Rows)
                    {
                        SDK_SAP.Clases.DocumentLines line = new SDK_SAP.Clases.DocumentLines();

                        line.ItemCode        = Convert.ToString(item.Cells["ItemCode"].Value);
                        line.ItemDescription = Convert.ToString(item.Cells["ItemName"].Value);
                        line.Quantity        = Convert.ToDouble(item.Cells["Quantity"].Value);
                        line.Facturado       = Convert.ToDouble(item.Cells["FacturadoQty"].Value);
                        line.Currency        = Convert.ToString(item.Cells["Currency"].Value);
                        line.WarehouseCode   = Convert.ToString(item.Cells["WhsCode"].Value);
                        line.Price           = Convert.ToDouble(item.Cells["Price"].Value);
                        line.U_Comentario    = Convert.ToString(item.Cells["U_Comentario"].Value);
                        line.ManBtchNum      = Convert.ToString(item.Cells["ManBtchNum"].Value);

                        line.BaseEntry = (int?)(item.Cells["BaseEntry"].Value != DBNull.Value ? item.Cells["BaseEntry"].Value : null);
                        line.BaseLine  = (int?)(item.Cells["BaseLine"].Value != DBNull.Value ? item.Cells["BaseLine"].Value : null);
                        line.BaseType  = (int?)(item.Cells["BaseType"].Value != DBNull.Value ? item.Cells["BaseType"].Value : null);

                        document.Lines.Add(line);
                    }

                    #region Lotes
                    bool viewLotes = false;
                    bool finalizar = true;
                    bool LotesOk   = true;
                    //do
                    //{
                    viewLotes = false;
                    finalizar = true;
                    foreach (var item in document.Lines)
                    {
                        if (item.ManBtchNum.Equals("Y"))
                        {
                            if (item.Quantity != item.LotesList.Sum(lote_item => lote_item.Cantidad))
                            {
                                viewLotes = true;
                            }
                            foreach (var lote in item.LotesList)
                            {
                                if (!string.IsNullOrEmpty(lote.Pedimento))
                                {
                                    viewLotes = true;
                                }
                                if (!string.IsNullOrEmpty(lote.Aduana))
                                {
                                    viewLotes = true;
                                }
                            }
                        }
                    }

                    if (viewLotes)
                    {
                        frmLotes form = new frmLotes(document, tbl_Lotes);
                        if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                        {
                            return;
                        }
                        else
                        {
                            tbl_Lotes = form.Tbl_lotes;
                        }
                    }

                    foreach (var item in document.Lines)
                    {
                        if (item.ManBtchNum.Equals("Y"))
                        {
                            if (item.Facturado != item.LotesList.Sum(lote_item => lote_item.Cantidad))
                            {
                                finalizar = false;
                            }
                        }
                    }

                    foreach (var item in document.Lines)
                    {
                        if (item.ManBtchNum.Equals("Y"))
                        {
                            foreach (var lote in item.LotesList)
                            {
                                if (string.IsNullOrEmpty(lote.Pedimento))
                                {
                                    LotesOk = false;
                                }
                                if (string.IsNullOrEmpty(lote.Aduana))
                                {
                                    LotesOk = false;
                                }
                            }
                        }
                    }
                    //}
                    //while (!finalizar);
                    if (!LotesOk)
                    {
                        this.SetMensaje("Falta ingresar informacion Aduana|Pedimento", 5000, Color.Red, Color.White);
                        return;
                    }


                    #endregion
                    if (finalizar)
                    {
                        SDK_SAP.DI.Documents doc = new SDK_SAP.DI.Documents(10008);
                        SDK_SAP.DI.Connection.InitializeConnection(10008);
                        SDK_SAP.DI.Connection.StartConnection();

                        txtFolio.Text = doc.AddDocument("OPDN", document).ToString();

                        SDK_SAP.DI.Connection.CloseConnection();

                        this.SetMensaje("Listo", 5000, Color.Green, Color.Black);
                        DocumentMode = "Creado";
                    }
                }
                catch (Exception ex)
                {
                    this.SetMensaje(ex.Message, 5000, Color.Red, Color.White);
                }
                finally
                {
                    Cursor.Current = Cursors.Arrow;
                }
                #endregion
                this.Formulario_Modo();
            }

            if (btnCrear.Text == "Actualizar")
            {
            }
        }
コード例 #2
0
        private void btnEntrega_Click(object sender, EventArgs e)
        {
            try
            {
                btnConsultar.Focus();

                SDK_SAP.Clases.Document doc = new SDK_SAP.Clases.Document();

                DataTable tbl_Datos = new DataTable();
                tbl_Datos       = dgvDatos.DataSource as DataTable;
                doc.DocType     = "dDocument_Items";
                doc.DocDate     = DateTime.Now;
                doc.CardCode    = Convert.ToString(tbl_Datos.Rows[0]["CardCode"]);
                doc.DocCurrency = Convert.ToString(tbl_Datos.Rows[0]["DocCur"]);

                doc.U_Cuenta  = Convert.ToString(tbl_Datos.Rows[0]["U_Cuenta"]);
                doc.U_MPAGO2  = Convert.ToString(tbl_Datos.Rows[0]["U_MPAGO2"]);
                doc.U_TipoOV  = Convert.ToString(tbl_Datos.Rows[0]["U_TipoOV"]);
                doc.U_Titular = Convert.ToString(tbl_Datos.Rows[0]["U_Titular"]);
                doc.U_TPedido = Convert.ToString(tbl_Datos.Rows[0]["U_TPedido"]);
                doc.U_OC      = Convert.ToString(tbl_Datos.Rows[0]["U_OC"]);

                doc.Series = Convert.ToInt32(tbl_Datos.Rows[0]["Series"]);

                /*
                 * doc.U_LugarExp = Convert.ToString(tbl_Heder.Rows[0]["LugarExp"]);
                 * doc.FE_Calle = Convert.ToString(tbl_Heder.Rows[0]["Calle"]);
                 * doc.FE_NoExt = Convert.ToString(tbl_Heder.Rows[0]["NoExt"]);
                 * doc.FE_NoInt = Convert.ToString(tbl_Heder.Rows[0]["NoInt"]);
                 * doc.FE_Colonia = Convert.ToString(tbl_Heder.Rows[0]["Colonia"]);
                 * doc.FE_Municipio = Convert.ToString(tbl_Heder.Rows[0]["Municipio"]);
                 * doc.FE_Estado = Convert.ToString(tbl_Heder.Rows[0]["Estado"]);
                 * doc.FE_Pais = "México";
                 * doc.FE_CP = Convert.ToString(tbl_Heder.Rows[0]["CP"]);
                 */

                foreach (DataRow item in tbl_Datos.Rows)
                {
                    if (Convert.ToBoolean(item["Seleccionar"]))
                    {
                        SDK_SAP.Clases.DocumentLines lineDoc = new SDK_SAP.Clases.DocumentLines();
                        lineDoc.ItemCode      = Convert.ToString(item["ItemCode"]);
                        lineDoc.Quantity      = Convert.ToDouble(item["Surtido"]);
                        lineDoc.Currency      = Convert.ToString(item["Currency"]);
                        lineDoc.WarehouseCode = Convert.ToString(item["WhsCode"]);
                        lineDoc.Price         = Convert.ToDouble(item["Price"]);
                        lineDoc.MeasureUnit   = Convert.ToString(item["SalUnitMsr"]);
                        if (item["U_PReal"] != DBNull.Value)
                        {
                            lineDoc.U_PReal = Convert.ToDouble(item["U_PReal"]);
                        }
                        if (item["U_Comentario"] != DBNull.Value)
                        {
                            lineDoc.U_Comentario = Convert.ToString(item["U_Comentario"]);
                        }
                        lineDoc.ManBtchNum = Convert.ToString(item["ManBtchNum"]);

                        SDK_SAP.Clases.Lotes lote = new SDK_SAP.Clases.Lotes();
                        if (lineDoc.ManBtchNum.Equals("Y"))
                        {
                            DataTable tbl_Lot = lote.getLotes(lineDoc.ItemCode, lineDoc.WarehouseCode, lineDoc.Quantity);
                            foreach (DataRow itemLote in tbl_Lot.Rows)
                            {
                                SDK_SAP.Clases.Lotes oLot = new SDK_SAP.Clases.Lotes();
                                oLot.Lote     = itemLote.Field <string>("BatchNum");
                                oLot.Cantidad = (double)itemLote.Field <decimal>("Quantity");
                                lineDoc.LotesList.Add(oLot);
                            }
                        }

                        lineDoc.BaseEntry = Convert.ToInt32(item["DocEntry"]);
                        lineDoc.BaseLine  = Convert.ToInt32(item["LineNum"]);
                        lineDoc.BaseType  = Convert.ToInt32(tbl_Datos.Rows[0]["ObjType"]);

                        doc.Lines.Add(lineDoc);
                    }
                }

                SDK_SAP.DI.Documents diAPI_Document = new SDK_SAP.DI.Documents(20011);

                decimal FolioSap = diAPI_Document.AddDocument("ODLN", doc);

                this.SetMensaje("Listo! Folio: " + FolioSap, 5000, Color.Green, Color.Black);

                this.OnLoad(e);
            }
            catch (Exception ex)
            {
                this.SetMensaje(ex.Message, 5000, Color.Red, Color.White);
            }
        }