//ok public decimal CerrarOrdenCompra(SDK.Documentos.frmDocumentos form, SDK_SAP.Clases.Document document) { SAPbobsCOM.Documents oDocument = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); oDocument.GetByKey(Convert.ToInt32(document.DocEntry)); #region Detalle for (int i = 0; i < oDocument.Lines.Count; i++) { oDocument.Lines.SetCurrentLine(i); if (oDocument.Lines.LineStatus != SAPbobsCOM.BoStatus.bost_Close) { oDocument.Lines.LineStatus = SAPbobsCOM.BoStatus.bost_Close; } } #endregion if (oDocument.Update() != 0) { throw new Exception("Error [" + oCompany.GetLastErrorDescription() + "]"); } else { #region Datos SAP form.txtFolio.Text = oCompany.GetNewObjectKey(); oDocument.GetByKey(Convert.ToInt32(form.txtFolio.Text)); form.txtFolio.Text = oDocument.DocNum.ToString(); if (SAPbobsCOM.BoStatus.bost_Close == oDocument.DocumentStatus) { form.txtStatus.Text = "Cerrado"; } else if (SAPbobsCOM.BoStatus.bost_Open == oDocument.DocumentStatus) { form.txtStatus.Text = "Abierto"; } #endregion } this.CloseConnection(); return(oDocument.DocNum); }
public frmDocumentos(int _idDocument, decimal _DocKey, int _ObjType, decimal _WtmCode, decimal _WddCode) { InitializeComponent(); typeDocument = "Borrador"; DocumentSAP = new SDK_SAP.Clases.Document(); dgvDatos.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom; // I N I C I A L I Z A R IdDocument = _idDocument; config = new SDK.Configuracion.SDK_Configuracion_Document(IdDocument, this); config.ModeDocument = "New"; config.StartEmpty(); IVA = config.IVA1; this.AccessibleDescription = "SDK " + this.Text; txtFolio.Text = _DocKey.ToString(); DocKey = _DocKey; ObjType = _ObjType; WtmCode = _WtmCode; WddCode = _WddCode; }
//ok public decimal ActualizarDocumento(SDK.Documentos.frmDocumentos form, SDK_SAP.Clases.Document documentConCambios) { //SAPbobsCOM.Documents oDocumentCopy = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); SAPbobsCOM.Documents oDocumento = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); oDocumento.GetByKey(Convert.ToInt32(documentConCambios.DocEntry)); //oDocumentCopy = oDocumento; oDocumento.DocDueDate = form.dtpDocDueDate.Value; #region Encabezado if (!string.IsNullOrEmpty(form.txtNumAtCard.Text)) { oDocumento.NumAtCard = form.txtNumAtCard.Text; } if (!string.IsNullOrEmpty(form.txtComments.Text)) { oDocumento.Comments = form.txtComments.Text; } #endregion #region Detalle foreach (UltraGridRow row in form.dgvDatos.Rows) { if (!row.IsAddRow) { //si la linea ya existe la linea solo actiaizar if (Convert.ToInt32(row.Cells["LineNum"].Value == DBNull.Value ? -1 : row.Cells["LineNum"].Value) > -1) { oDocumento.Lines.SetCurrentLine(Convert.ToInt32(row.Index)); oDocumento.Lines.Quantity = Convert.ToDouble(row.Cells["Quantity"].Value); if (row.Cells["ShipDate"].Value != DBNull.Value) { oDocumento.Lines.ShipDate = Convert.ToDateTime(row.Cells["ShipDate"].Value); } if (row.Cells["U_Comentario"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_Comentario").Value = row.Cells["U_Comentario"].Value; } else { oDocumento.Lines.UserFields.Fields.Item("U_Comentario").Value = String.Empty; } if (row.Cells["U_Vendedor"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_Vendedor").Value = row.Cells["U_Vendedor"].Value; } else { oDocumento.Lines.UserFields.Fields.Item("U_Vendedor").Value = String.Empty; } if (row.Cells["WhsCode"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_Warehouse").Value = Convert.ToString(row.Cells["WhsCode"].Value); } if (row.Cells["ShipDate"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_ShipDate").Value = Convert.ToDateTime(row.Cells["ShipDate"].Value); } else { oDocumento.Lines.UserFields.Fields.Item("U_ShipDate").Value = oDocumento.DocDueDate; } } else { oDocumento.Lines.Add(); oDocumento.Lines.ItemCode = Convert.ToString(row.Cells["ItemCode"].Value); oDocumento.Lines.Quantity = Convert.ToDouble(row.Cells["Quantity"].Value); oDocumento.Lines.Currency = Convert.ToString(row.Cells["Currency"].Value); oDocumento.Lines.UnitPrice = Convert.ToDouble(row.Cells["Price"].Value); oDocumento.Lines.WarehouseCode = Convert.ToString(row.Cells["WhsCode"].Value); if (row.Cells["ShipDate"].Value != DBNull.Value) { oDocumento.Lines.ShipDate = Convert.ToDateTime(row.Cells["ShipDate"].Value); } if (row.Cells["U_Comentario"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_Comentario").Value = row.Cells["U_Comentario"].Value; } else { oDocumento.Lines.UserFields.Fields.Item("U_Comentario").Value = String.Empty; } if (row.Cells["U_Vendedor"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_Vendedor").Value = row.Cells["U_Vendedor"].Value; } else { oDocumento.Lines.UserFields.Fields.Item("U_Vendedor").Value = String.Empty; } if (row.Cells["WhsCode"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_Warehouse").Value = Convert.ToString(row.Cells["WhsCode"].Value); } if (row.Cells["ShipDate"].Value != DBNull.Value) { oDocumento.Lines.UserFields.Fields.Item("U_ShipDate").Value = Convert.ToDateTime(row.Cells["ShipDate"].Value); } else { oDocumento.Lines.UserFields.Fields.Item("U_ShipDate").Value = oDocumento.DocDueDate; } } } } #endregion if (oDocumento.Update() != 0) { throw new Exception("Error [" + oCompany.GetLastErrorDescription() + "]"); } else { #region Datos SAP form.txtFolio.Text = oCompany.GetNewObjectKey(); oDocumento.GetByKey(Convert.ToInt32(form.txtFolio.Text)); form.txtFolio.Text = oDocumento.DocNum.ToString(); if (SAPbobsCOM.BoStatus.bost_Close == oDocumento.DocumentStatus) { form.txtStatus.Text = "Cerrado"; } else if (SAPbobsCOM.BoStatus.bost_Open == oDocumento.DocumentStatus) { form.txtStatus.Text = "Abierto"; } //form.btnCrear.Enabled = false; #endregion } this.CloseConnection(); return(oDocumento.DocNum); }
//ok public SAPbobsCOM.Documents EliminarLineaOrdenCompra(SDK.Documentos.frmDocumentos form, SDK_SAP.Clases.Document document, int Line) { SAPbobsCOM.Documents oDocument = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); SAPbobsCOM.Documents oDocumentCopy = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); oDocument.GetByKey(Convert.ToInt32(document.DocEntry)); oDocumentCopy = oDocument; #region Eliminar Linea oDocument.Lines.SetCurrentLine(Line); if (oDocument.Lines.LineStatus != SAPbobsCOM.BoStatus.bost_Close) { oDocument.Lines.Delete(); } if (oDocument.Update() != 0) { throw new Exception("Error [" + oCompany.GetLastErrorDescription() + "]"); } #endregion else { #region Datos SAP form.txtFolio.Text = oCompany.GetNewObjectKey(); oDocumentCopy.GetByKey(Convert.ToInt32(form.txtFolio.Text)); form.txtFolio.Text = oDocumentCopy.DocNum.ToString(); if (SAPbobsCOM.BoStatus.bost_Close == oDocumentCopy.DocumentStatus) { form.txtStatus.Text = "Cerrado"; } else if (SAPbobsCOM.BoStatus.bost_Open == oDocumentCopy.DocumentStatus) { form.txtStatus.Text = "Abierto"; } //form.btnCrear.Enabled = false; #endregion } this.CloseConnection(); return(oDocument); }
public frmLotes(SDK_SAP.Clases.Document doc, DataTable tbl, bool qty = false) { InitializeComponent(); Document = doc; tbl_lotes = tbl.Copy(); tbl_documets.Columns.Add("DocNum", typeof(double)); tbl_documets.Columns.Add("ID", typeof(string)); tbl_documets.Columns.Add("ItemCode", typeof(string)); tbl_documets.Columns.Add("ItemName", typeof(string)); tbl_documets.Columns.Add("WhsCode", typeof(string)); tbl_documets.Columns.Add("Quantity", typeof(double)); tbl_documets.Columns.Add("Total Creado", typeof(double)); #region Articulos que necesitan Lotes foreach (var item in Document.Lines) { if (item.ManBtchNum.Equals("Y")) { DataRow row = tbl_documets.NewRow(); string id = item.ItemCode + item.WarehouseCode + (item.BaseEntry == null ? 0 : item.BaseEntry) + (item.BaseLine == null ? 0 : item.BaseLine); row["ID"] = id; row["ItemCode"] = item.ItemCode; row["ItemName"] = item.ItemDescription; row["WhsCode"] = item.WarehouseCode; if (!qty) { row["Quantity"] = item.Facturado * item.NumPerMsr; } else { row["Quantity"] = item.Quantity * item.NumPerMsr; } if (tbl_lotes.Columns.Count > 0) { row["Total Creado"] = (from l in tbl_lotes.AsEnumerable() where l.Field <string>("ID").Equals(id) select l.Field <double>("Cantidad")).Sum(); } tbl_documets.Rows.Add(row); } } #endregion #region Lotes if (tbl.Columns.Count <= 0) { tbl_lotes.Columns.Add("ID", typeof(string)); tbl_lotes.Columns.Add("Lote", typeof(string)); tbl_lotes.Columns.Add("Cantidad", typeof(double)); tbl_lotes.Columns.Add("Pedimento", typeof(string)); tbl_lotes.Columns.Add("Aduana", typeof(string)); tbl_lotes.Columns.Add("Fecha de admisión", typeof(DateTime)); foreach (var item in Document.Lines) { if (item.ManBtchNum.Equals("Y")) { foreach (var lote in item.LotesList) { DataRow row = tbl_lotes.NewRow(); row["ID"] = item.ItemCode + item.WarehouseCode + "" + (item.BaseEntry == null ? 0 : item.BaseEntry) + "" + (item.BaseLine == null ? 0 : item.BaseLine); row["Lote"] = lote.Lote; row["Cantidad"] = lote.Cantidad; row["Pedimento"] = lote.Pedimento; row["Aduana"] = lote.Aduana; row["Fecha de admisión"] = lote.FechaAdmision; tbl_lotes.Rows.Add(row); } } } } else { foreach (var item in Document.Lines) { if (item.ManBtchNum.Equals("Y")) { foreach (var lote in item.LotesList) { DataRow row = tbl_lotes.NewRow(); row["ID"] = item.ItemCode + item.WarehouseCode + "" + (item.BaseEntry == null ? 0 : item.BaseEntry) + "" + (item.BaseLine == null ? 0 : item.BaseLine); row["Lote"] = lote.Lote; row["Cantidad"] = lote.Cantidad; row["Pedimento"] = lote.Pedimento; row["Aduana"] = lote.Aduana; row["Fecha de admisión"] = lote.FechaAdmision; tbl_lotes.Rows.Add(row); } } } } #endregion }
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") { } }
public void txtFolio_KeyPress(object sender, KeyPressEventArgs e) { try { if ((int)e.KeyChar == (int)Keys.Enter) { if (string.IsNullOrEmpty(txtFolio.Text)) { SDK.Documentos.frmListadoDocumentos formulario = new frmListadoDocumentos(IdDocument, txtCardCode.Text.Replace('*', '%'), txtCardName.Text.Replace('*', '%'), dtpDocDate.Value, txtNumAtCard.Text.Replace('*', '%')); if (formulario.ShowDialog() == System.Windows.Forms.DialogResult.Yes) { txtFolio.Text = formulario.DocEntry.ToString(); typeDocument = formulario.Tipo; } else { //this.CleanScreen(); return; } } #region Documento Encontrado (dgvDatos.DataSource as DataTable).Rows.Clear(); DocumentSAP = new SDK_SAP.Clases.Document(); DocumentSAP = DocumentSAP.Fill_OPOR(Convert.ToDecimal(txtFolio.Text), ObjType, typeDocument); #region LLenar Form this.CleanScreen(); txtFolio.Text = DocumentSAP.DocNum.ToString(); txtCardCode.Text = DocumentSAP.CardCode; txtCardName.Text = DocumentSAP.CardName; txtMoneda.Text = DocumentSAP.DocCurrency; cbMoneda.SelectedValue = DocumentSAP.DocCurrency; txtNumAtCard.Text = DocumentSAP.NumAtCard; cbMoneda.Enabled = false; if (DocumentSAP.DocStatus == "C") { txtStatus.Text = "Cerrado"; btnCrear.Enabled = false; cerrarStripButton.Enabled = false; cerrarLíneaToolStripMenuItem.Enabled = false; agregarFilaToolStripMenuItem1.Enabled = false; tooStripDuplicar.Enabled = false; } else if (DocumentSAP.DocStatus == "O") { txtStatus.Text = "Abierto"; btnCrear.Enabled = true; cerrarStripButton.Enabled = true; cerrarLíneaToolStripMenuItem.Enabled = true; agregarFilaToolStripMenuItem1.Enabled = true; tooStripDuplicar.Enabled = true; } else if (DocumentSAP.DocStatus == "P") { txtStatus.Text = "Pendiente"; btnCrear.Text = "Autorizar"; btnCrear.Enabled = true; cerrarStripButton.Enabled = true; cerrarLíneaToolStripMenuItem.Enabled = true; agregarFilaToolStripMenuItem1.Enabled = true; tooStripDuplicar.Enabled = true; } else if (DocumentSAP.DocStatus == "A") { txtStatus.Text = "Autorizado"; btnCrear.Text = "Crear"; btnCrear.Enabled = true; cerrarStripButton.Enabled = false; cerrarLíneaToolStripMenuItem.Enabled = false; agregarFilaToolStripMenuItem1.Enabled = false; tooStripDuplicar.Enabled = false; } else if (DocumentSAP.DocStatus == "R") { txtStatus.Text = "Rechazado"; btnCrear.Text = "Crear"; btnCrear.Enabled = false; cerrarStripButton.Enabled = false; cerrarLíneaToolStripMenuItem.Enabled = false; agregarFilaToolStripMenuItem1.Enabled = false; tooStripDuplicar.Enabled = false; } dtpDocDate.Value = DocumentSAP.DocDate; dtpDocDueDate.Value = DocumentSAP.DocDueDate; txtComments.Text = DocumentSAP.Comments; txtSubtotal.Text = (DocumentSAP.DocTotal - DocumentSAP.VatSum).ToString("N2"); txtIVA.Text = DocumentSAP.VatSum.ToString("N2"); txtTotal.Text = DocumentSAP.DocTotal.ToString("N2"); #region Detalle foreach (var item in DocumentSAP.Lines) { DataRow row = (dgvDatos.DataSource as DataTable).NewRow(); row["ItemCode"] = item.ItemCode; row["ItemName"] = item.ItemDescription; row["Quantity"] = item.Quantity; row["OpenQty"] = item.OpenQty; row["Price"] = item.Price; row["Currency"] = item.Currency; row["WhsCode"] = item.WarehouseCode; row["WhsName"] = item.WarehouseCode + " | " + item.WarehouseName; row["LineNum"] = item.LineNum; row["Rate"] = item.Rate; row["ShipDate"] = item.ShipDate; row["LineTotal"] = item.LineTotal; row["LineStatus"] = item.LineStatus; row["U_Vendedor"] = item.U_Vendedor; row["SlpCode"] = item.U_Vendedor; row["U_Comentario"] = item.U_Comentario; row["VolumenU"] = item.VolumenU; row["PesoU"] = item.PesoU; row["OnHand"] = item.OnHand; row["Ideal"] = item.Ideal; row["ABC"] = item.ABC; (dgvDatos.DataSource as DataTable).Rows.Add(row); (dgvDatos.DataSource as DataTable).AcceptChanges(); } #endregion #endregion #endregion #region Eliminar /* #region Documento Encontrado * (dgvDatos.DataSource as DataTable).Rows.Clear(); * * Document = new SDKDatos.SDK_OPOR(); * Document = Document.Fill(Convert.ToDecimal(txtFolio.Text)); * #region LLenar Form * this.CleanScreen(); * txtFolio.Text = Document.DocNum.ToString(); * txtCardCode.Text = Document.CardCode; * txtCardName.Text = Document.CardName; * txtMoneda.Text = Document.DocCur; * cbMoneda.SelectedValue = Document.DocCur; * txtNumAtCard.Text = Document.NumAtCard; * * cbMoneda.Enabled = false; * if (Document.DocStatus == "C") * { * txtStatus.Text = "Cerrado"; * btnCrear.Enabled = false; * cerrarStripButton.Enabled = false; * * cerrarLíneaToolStripMenuItem.Enabled = false; * agregarFilaToolStripMenuItem1.Enabled = false; * tooStripDuplicar.Enabled = false; * } * else if (Document.DocStatus == "O") * { * txtStatus.Text = "Abierto"; * btnCrear.Enabled = true; * cerrarStripButton.Enabled = true; * cerrarLíneaToolStripMenuItem.Enabled = true; * agregarFilaToolStripMenuItem1.Enabled = true; * tooStripDuplicar.Enabled = true; * } * * dtpDocDate.Value = Document.DocDate; * dtpDocDueDate.Value = Document.DocDueDate; * txtComments.Text = Document.Comments; * txtSubtotal.Text = (Document.DocTotal - Document.VatSum).ToString("N2"); * txtIVA.Text = Document.VatSum.ToString("N2"); * txtTotal.Text = Document.DocTotal.ToString("N2"); * #region Detalle * foreach (SDKDatos.SDK_POR1 item in Document.Lines) * { * DataRow row = (dgvDatos.DataSource as DataTable).NewRow(); * row["ItemCode"] = item.ItemCode; * row["ItemName"] = item.Dscription; * row["Quantity"] = item.Quantity; * row["OpenQty"] = item.OpenQty; * row["Price"] = item.Price; * row["Currency"] = item.Currency; * row["WhsCode"] = item.Whscode; * row["WhsName"] = item.Whscode + " | " + item.WhsName; * row["LineNum"] = item.LineNum; * row["Rate"] = item.Rate; * row["ShipDate"] = item.ShipDate; * row["LineTotal"] = item.LineTotal; * row["LineStatus"] = item.LineStatus; * row["U_Vendedor"] = item.U_Vendedor; * row["SlpCode"] = item.U_Vendedor; * row["U_Comentario"] = item.U_Comentario; * row["VolumenU"] = item.VolumenU; * row["PesoU"] = item.PesoU; * * (dgvDatos.DataSource as DataTable).Rows.Add(row); * * (dgvDatos.DataSource as DataTable).AcceptChanges(); * } #endregion #endregion * #endregion */ #endregion txtCardName.ReadOnly = true; txtCardName.ReadOnly = true; } #region solo lectura; if (ReadOnly) { btnCrear.Enabled = false; btnCancelar.Enabled = false; contextMenu.Enabled = false; foreach (var item in dgvDatos.DisplayLayout.Bands[0].Columns) { item.CellActivation = Activation.NoEdit; } } #endregion } catch (Exception ex) { this.SetMensaje("Error al cargar OC: " + ex.Message, 5000, Color.Red, Color.White); } }
private void btnCrear_Click(object sender, EventArgs e) { if (btnCrear.Text == "Crear") { #region Orden de compra if (string.IsNullOrEmpty(txtMoneda.Text)) { this.SetMensaje("Campo MONEDA obligatorio", 5000, Color.Red, Color.White); return; } #region Crear try { #region Encabezado DocumentSAP = new SDK_SAP.Clases.Document(); Cursor.Current = Cursors.WaitCursor; DocumentSAP.CardCode = txtCardCode.Text; DocumentSAP.Series = 15; if (!String.IsNullOrWhiteSpace(txtFolio.Text)) { DocumentSAP.DocNum = Convert.ToInt32(txtFolio.Text); } else { DocumentSAP.DocNum = 0; } DocumentSAP.DocRate = (double)Rate; DocumentSAP.DocDate = dtpDocDate.Value; DocumentSAP.DocDueDate = dtpDocDueDate.Value; DocumentSAP.DocType = "dDocument_Items"; DocumentSAP.DocCurrency = txtMoneda.Text; if (!string.IsNullOrEmpty(txtNumAtCard.Text)) { DocumentSAP.NumAtCard = txtNumAtCard.Text; } if (!string.IsNullOrEmpty(txtComments.Text)) { DocumentSAP.Comments = txtComments.Text; } DocumentSAP.DocTotal = Convert.ToDouble(txtTotal.Text); DocumentSAP.VatSum = Convert.ToDouble(txtIVA.Text); #endregion foreach (var item in dgvDatos.Rows) { #region Detalles 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.Currency = Convert.ToString(item.Cells["Currency"].Value); line.WarehouseCode = Convert.ToString(item.Cells["WhsCode"].Value); if (item.Cells["ShipDate"].Value != DBNull.Value) { line.ShipDate = Convert.ToDateTime(item.Cells["ShipDate"].Value); } line.U_Comentario = Convert.ToString(item.Cells["U_Comentario"].Value); line.U_Vendedor = Convert.ToString(item.Cells["U_Vendedor"].Value); line.Price = Convert.ToDouble(item.Cells["Price"].Value); line.Rate = Convert.ToDouble(item.Cells["Rate"].Value); line.LineTotal = Convert.ToDouble(item.Cells["LineTotal"].Value); if (item.Cells["OnHand"].Value != DBNull.Value) { line.OnHand = Convert.ToDouble(item.Cells["OnHand"].Value); } if (item.Cells["Ideal"].Value != DBNull.Value) { line.Ideal = Convert.ToDouble(item.Cells["Ideal"].Value); } if (item.Cells["VI"].Value != DBNull.Value) { line.VI = Convert.ToDouble(item.Cells["VI"].Value); } if (item.Cells["ABC"].Value != DBNull.Value) { line.ABC = Convert.ToString(item.Cells["ABC"].Value); } DocumentSAP.Lines.Add(line); #endregion } if (!txtStatus.Text.Equals("Autorizado")) { #region Borrador DocumentSAP.DocType = ObjType.ToString(); txtFolio.Text = DocumentSAP.SaveDraft(DocumentSAP).ToString(); DocumentSAP = DocumentSAP.Fill_OPOR(DocumentSAP.DocNum, ObjType, "Borrador"); txtFolio.Text = DocumentSAP.DocNum.ToString(); if (DocumentSAP.DocStatus.Equals("P")) { txtStatus.Text = "Pendiente"; } else if (DocumentSAP.DocStatus.Equals("R")) { txtStatus.Text = "Rechazado"; } else if (DocumentSAP.DocStatus.Equals("A")) { txtStatus.Text = "Autorizado"; } typeDocument = "Borrador"; var kea = new KeyPressEventArgs(Convert.ToChar(13)); this.txtFolio_KeyPress(sender, kea); this.SetMensaje("Listo", 5000, Color.Green, Color.Black); #endregion } if (txtStatus.Text.Equals("Autorizado")) { SDK.SDKDatos.SDK_DI sdk = new SDKDatos.SDK_DI(1);//--Orden de compra 1 sdk.CrearOrdenCompra(this).ToString(); this.SetMensaje("Listo", 5000, Color.Green, Color.Black); Object[] valuesOut = new Object[] { }; Datos.Connection connection = new Datos.Connection(); connection.Ejecutar("LOG", "sp_SDKDocumentosPrevios_test", new string[] { }, new string[] { "@TipoConsulta", "@ObjType", "@DocNum", "@DocNumSAP" }, ref valuesOut, 17, ObjType, DocumentSAP.DocNum, txtFolio.Text); /* #region SAP * SDK_SAP.DI.Connection.InitializeConnection(9); * SDK_SAP.DI.Connection.StartConnection(); * SDK_SAP.DI.Documents doc = new SDK_SAP.DI.Documents(9); * * txtFolio.Text = doc.AddDocument("ORDN", Document).ToString(); * * var kea = new KeyPressEventArgs(Convert.ToChar(13)); * this.txtFolio_KeyPress(sender, kea); * * SDK_SAP.DI.Connection.CloseConnection(); * this.SetMensaje("Listo", 5000, Color.Green, Color.Black); * DocumentMode = "Creado"; * * Object[] valuesOut = new Object[] { }; * Datos.Connection connection = new Datos.Connection(); * * connection.Ejecutar("LOG", * "sp_SDKDocumentosPrevios", * new string[] { }, * new string[] { "@TipoConsulta", "@ObjType", "@DocNum", "@DocNumSAP" }, * ref valuesOut, 17, ObjType, Document.DocNum, txtFolio.Text); #endregion */ } } catch (Exception ex) { this.SetMensaje(ex.Message, 5000, Color.Red, Color.White); } finally { Cursor.Current = Cursors.Arrow; } #endregion #endregion } if (btnCrear.Text == "Actualizar") { #region Modificar try { Cursor.Current = Cursors.WaitCursor; if (IdDocument == (int)SDK.Configuracion.SDK_Configuracion_Document.DocumentType.OrdenCompra) { SDK.SDKDatos.SDK_DI sdk = new SDKDatos.SDK_DI(1);//Orden de compra sdk.ActualizarDocumento(this, DocumentSAP).ToString(); this.SetMensaje("OC Actualizada correctamente", 5000, Color.Green, Color.Black); } } catch (Exception ex) { this.SetMensaje(ex.Message, 5000, Color.Red, Color.White); } finally { Cursor.Current = Cursors.Arrow; } #endregion } if (btnCrear.Text == "Autorizar") { #region Autorizar using (SqlConnection connection1 = new SqlConnection(Datos.Clases.Constantes.conectionLog)) { connection1.Open(); SqlCommand command = new SqlCommand(); command.CommandText = "sp_SDKDocumentosPrevios"; command.Connection = connection1; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@TipoConsulta", 16); command.Parameters.AddWithValue("@DocNum", DocKey); command.Parameters.AddWithValue("@Comments", txtComments.Text); command.Parameters.AddWithValue("@WddCode", WddCode); command.Parameters.AddWithValue("@userID", ClasesSGUV.Login.Id_Usuario); try { command.ExecuteNonQuery(); connection1.Close(); MessageBox.Show("Listo", "HalcoNET", MessageBoxButtons.OK, MessageBoxIcon.Information); this.SetMensaje("Listo", 5000, Color.Green, Color.Black); DocumentSAP = DocumentSAP.Fill_OPOR(Convert.ToDecimal(txtFolio.Text), 22, "Borrador"); txtFolio.Text = DocumentSAP.DocNum.ToString(); if (DocumentSAP.DocStatus.Equals("P")) { txtStatus.Text = "Pendiente"; } else if (DocumentSAP.DocStatus.Equals("R")) { txtStatus.Text = "Rechazado"; } else if (DocumentSAP.DocStatus.Equals("A")) { txtStatus.Text = "Autorizado"; } this.SetMensaje("Listo", 5000, Color.Green, Color.Black); btnCrear.Enabled = false; } catch (Exception ex) { this.SetMensaje(ex.Message, 5000, Color.Red, Color.White); } } #endregion } }
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); } }