public decimal ActualizarOrdenCompra(SDK.Documentos.frmDocumentos form, SDK_OPOR document) { SAPbobsCOM.Documents oDocument = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); oDocument.GetByKey(Convert.ToInt32(document.DocEntry)); #region Encabezado if (!string.IsNullOrEmpty(form.txtNumAtCard.Text)) { oDocument.NumAtCard = form.txtNumAtCard.Text; } if (!string.IsNullOrEmpty(form.txtComments.Text)) { oDocument.Comments = form.txtComments.Text; } oDocument.DocDueDate = form.dtpDocDueDate.Value; #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) > -1) { oDocument.Lines.SetCurrentLine(Convert.ToInt32(row.Cells["LineNum"].Value)); oDocument.Lines.Quantity = Convert.ToDouble(row.Cells["Quantity"].Value); if (row.Cells["ShipDate"].Value != DBNull.Value) { oDocument.Lines.ShipDate = Convert.ToDateTime(row.Cells["ShipDate"].Value); } if (row.Cells["U_Comentario"].Value != DBNull.Value) { oDocument.Lines.UserFields.Fields.Item("U_Comentario").Value = row.Cells["U_Comentario"].Value; } if (row.Cells["U_Vendedor"].Value != DBNull.Value) { oDocument.Lines.UserFields.Fields.Item("U_Vendedor").Value = row.Cells["U_Vendedor"].Value; } } else { oDocument.Lines.Add(); oDocument.Lines.ItemCode = Convert.ToString(row.Cells["ItemCode"].Value); oDocument.Lines.Quantity = Convert.ToDouble(row.Cells["Quantity"].Value); oDocument.Lines.Currency = Convert.ToString(row.Cells["Currency"].Value); oDocument.Lines.UnitPrice = Convert.ToDouble(row.Cells["Price"].Value); oDocument.Lines.WarehouseCode = Convert.ToString(row.Cells["WhsCode"].Value); if (row.Cells["ShipDate"].Value != DBNull.Value) { oDocument.Lines.ShipDate = Convert.ToDateTime(row.Cells["ShipDate"].Value); } oDocument.Lines.UserFields.Fields.Item("U_Comentario").Value = Convert.ToString(row.Cells["U_Comentario"].Value); oDocument.Lines.UserFields.Fields.Item("U_Vendedor").Value = Convert.ToString(row.Cells["U_Vendedor"].Value); //if (oDocument.Update() != 0) // throw new Exception("Error [" + oCompany.GetLastErrorDescription() + "]"); } } } #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"; } //form.btnCrear.Enabled = false; #endregion } this.CloseConnection(); return(oDocument.DocNum); }
public SDK_OPOR Fill(decimal _docEntry) { SDK_OPOR document = new SDK_OPOR(); using (SqlConnection connection = new SqlConnection(Datos.Clases.Constantes.conectionLog)) { using (SqlCommand command = new SqlCommand(nameProc, connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@TipoConsulta", 4); command.Parameters.AddWithValue("@Key", _docEntry); DataTable tbl_Header = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = command; da.Fill(tbl_Header); document.DocEntry = tbl_Header.Rows[0].Field <Int32>("DocEntry"); document.DocNum = tbl_Header.Rows[0].Field <Int32>("DocNum"); document.CardCode = tbl_Header.Rows[0].Field <string>("CardCode"); document.CardName = tbl_Header.Rows[0].Field <string>("CardName"); document.DocCur = tbl_Header.Rows[0].Field <string>("DocCur"); document.NumAtCard = tbl_Header.Rows[0].Field <string>("NumAtCard"); document.DocStatus = tbl_Header.Rows[0].Field <string>("DocStatus"); document.DocDate = tbl_Header.Rows[0].Field <DateTime>("DocDate"); document.DocDueDate = tbl_Header.Rows[0].Field <DateTime>("DocDueDate"); document.Comments = tbl_Header.Rows[0].Field <string>("Comments"); document.FolioProv = tbl_Header.Rows[0].Field <string>("U_FPROV"); //document.TaxCode = tbl.Rows[0].Field<string>("TaxCode"); document.DocTotal = document.DocCur == "USD" ? tbl_Header.Rows[0].Field <decimal>("DocTotalFC") : tbl_Header.Rows[0].Field <decimal>("DocTotal"); document.VatSum = document.DocCur == "USD" ? tbl_Header.Rows[0].Field <decimal>("VatSumFC") : tbl_Header.Rows[0].Field <decimal>("VatSum"); } } using (SqlConnection connection = new SqlConnection(Datos.Clases.Constantes.conectionLog)) { using (SqlCommand command = new SqlCommand(nameProc, connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@TipoConsulta", 5); command.Parameters.AddWithValue("@Key", document.DocEntry); DataTable tbl_Details = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = command; da.Fill(tbl_Details); foreach (DataRow item in tbl_Details.Rows) { SDK_POR1 line = new SDK_POR1(); line.LineNum = item.Field <Int32>("LineNum"); line.ItemCode = item.Field <string>("ItemCode"); line.Dscription = item.Field <string>("Dscription"); line.Quantity = item.Field <decimal>("Quantity"); line.OpenQty = item.Field <decimal>("OpenQty"); line.Price = item.Field <decimal>("Price"); line.Whscode = item.Field <string>("Whscode"); line.WhsName = item.Field <string>("WhsName"); line.LineTotal = item.Field <decimal>("LineTotal"); line.ShipDate = item.Field <DateTime>("ShipDate"); line.LineStatus = item.Field <string>("LineStatus"); line.U_Comentario = item.Field <string>("U_Comentario"); line.U_Vendedor = item.Field <string>("U_Vendedor"); line.Rate = item.Field <string>("Currency") == document.DocCur ? 1 : item.Field <decimal>("Rate") == decimal.Zero ? 1 : item.Field <decimal>("Rate"); line.Currency = item.Field <string>("Currency"); line.PesoU = item.Field <decimal>("BWeight1"); line.VolumenU = item.Field <decimal>("BVolume"); document.Lines.Add(line); } } } return(document); }