Ejemplo n.º 1
0
        public productDto GetProduct(ref OperationResult pobjOperationResult, string v_ProductId)
        {
            //mon.IsActive = true;
            try
            {
                SigesoftEntitiesModel dbContext    = new SigesoftEntitiesModel();
                productDto            objDtoEntity = null;

                var objEntity = (from a in dbContext.product
                                 where a.v_ProductId == v_ProductId
                                 select a).FirstOrDefault();

                if (objEntity != null)
                {
                    objDtoEntity = productAssembler.ToDTO(objEntity);
                }

                pobjOperationResult.Success = 1;
                return(objDtoEntity);
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                return(null);
            }
        }
 public HttpResponseMessage Delete(productDto p)
 {
     if (rblh.DeleteProduct(p))
     {
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError));
     }
 }
 public HttpResponseMessage Post([FromBody] productDto p)
 {
     if (rblh.AddProduct(p))
     {
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError));
     }
 }
Ejemplo n.º 4
0
        private void LoadData()
        {
            OperationResult objOperationResult = new OperationResult();

            ////Llenado de combos
            Utils.LoadComboTreeBoxList(ddlCategoryId, BLL.Utils.GetDataHierarchyForComboTreeBox(ref objOperationResult, 103, null), DropDownListAction.Select);

            Utils.LoadDropDownList(ddlMeasurementUnitId, "Value1", "Id", BLL.Utils.GetDataHierarchyForCombo(ref objOperationResult, 105, null), DropDownListAction.Select);

            dtpExpirationDate.CustomFormat = "dd/MM/yyyy";

            if (_Mode == "New")
            {
                // Additional logic here.
            }
            else if (_Mode == "Edit")
            {
                // Get the Entity Data

                _productDto = _objBL.GetProduct(ref objOperationResult, _ProductId);

                ComboTreeNode nodoABuscar = ddlCategoryId.AllNodes.First(x => x.Tag.ToString() == _productDto.i_CategoryId.ToString());
                ddlCategoryId.SelectedNode = nodoABuscar;
                txtName.Text         = _productDto.v_Name;
                txtGenericName.Text  = _productDto.v_GenericName;
                txtBarCode.Text      = _productDto.v_BarCode;
                txtBarCode.Text      = _productDto.v_ProductCode;
                txtBrand.Text        = _productDto.v_Brand;
                txtModel.Text        = _productDto.v_Model;
                txtSerialNumber.Text = _productDto.v_SerialNumber;
                if (_productDto.d_ExpirationDate == null)
                {
                    dtpExpirationDate.Checked = false;
                }
                else
                {
                    dtpExpirationDate.Checked = true;
                    dtpExpirationDate.Value   = (DateTime)_productDto.d_ExpirationDate;
                }

                ddlMeasurementUnitId.SelectedValue = _productDto.i_MeasurementUnitId.ToString();
                txtReferentialCostPrice.Text       = _productDto.r_ReferentialCostPrice.ToString();
                txtReferentialSalesPrice.Text      = _productDto.r_ReferentialSalesPrice.ToString();
                txtPresentation.Text          = _productDto.v_Presentation;
                txtAdiccionalInformation.Text = _productDto.v_AdditionalInformation;
            }
        }
Ejemplo n.º 5
0
        public void UpdateProduct(ref OperationResult pobjOperationResult, productDto pobjDtoEntity, List <string> ClientSession)
        {
            //mon.IsActive = true;
            try
            {
                SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel();

                // Obtener la entidad fuente
                var objEntitySource = (from a in dbContext.product
                                       where a.v_ProductId == pobjDtoEntity.v_ProductId
                                       select a).FirstOrDefault();

                // Crear la entidad con los datos actualizados
                pobjDtoEntity.d_UpdateDate   = DateTime.Now;
                pobjDtoEntity.i_UpdateUserId = Int32.Parse(ClientSession[2]);

                product objEntity = productAssembler.ToEntity(pobjDtoEntity);

                // Copiar los valores desde la entidad actualizada a la Entidad Fuente
                dbContext.product.ApplyCurrentValues(objEntity);

                // Guardar los cambios
                dbContext.SaveChanges();

                pobjOperationResult.Success = 1;
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.ACTUALIZACION, "PRODUCTO", "v_ProductId=" + objEntity.v_ProductId.ToString(), Success.Ok, null);
                return;
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.ACTUALIZACION, "PRODUCTO", "v_ProductId=" + pobjDtoEntity.v_ProductId.ToString(), Success.Failed, pobjOperationResult.ExceptionMessage);
                return;
            }
        }
Ejemplo n.º 6
0
        public void AddProduct(ref OperationResult pobjOperationResult, productDto pobjDtoEntity, List <string> ClientSession)
        {
            //mon.IsActive = true;
            string NewId = "(No generado)";

            try
            {
                SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel();
                product objEntity = productAssembler.ToEntity(pobjDtoEntity);

                objEntity.d_InsertDate   = DateTime.Now;
                objEntity.i_InsertUserId = Int32.Parse(ClientSession[2]);
                objEntity.i_IsDeleted    = 0;

                // Autogeneramos el Pk de la tabla
                int intNodeId = int.Parse(ClientSession[0]);
                NewId = Common.Utils.GetNewId(intNodeId, Utils.GetNextSecuentialId(intNodeId, 6), "PI");;
                objEntity.v_ProductId = NewId;

                dbContext.AddToproduct(objEntity);
                dbContext.SaveChanges();

                pobjOperationResult.Success = 1;
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "PRODUCTO", "v_ProductId=" + NewId.ToString(), Success.Ok, null);
                return;
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "PRODUCTO", "v_ProductId=" + NewId.ToString(), Success.Failed, pobjOperationResult.ExceptionMessage);
                return;
            }
        }
Ejemplo n.º 7
0
 public bool DeleteProduct(productDto pd)
 {
     return(blsh.DeleteProduct(map.ProductDtoToProductDao(pd)));
 }
Ejemplo n.º 8
0
 public bool AddProduct(productDto pd)
 {
     return(blsh.AddProduct(map.ProductDtoToProductDao(pd)));
 }
Ejemplo n.º 9
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();

            if (uvProduct.Validate(true, false).IsValid)
            {
                if (txtName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para el producto.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (_Mode == "New")
                {
                    _productDto = new productDto();

                    _productDto.i_CategoryId   = Convert.ToInt32(ddlCategoryId.SelectedNode.Tag);
                    _productDto.v_Name         = txtName.Text.Trim();
                    _productDto.v_GenericName  = txtGenericName.Text.Trim();
                    _productDto.v_BarCode      = txtBarCode.Text.Trim();
                    _productDto.v_ProductCode  = txtBarCode.Text.Trim();
                    _productDto.v_Brand        = txtBrand.Text.Trim();
                    _productDto.v_Model        = txtModel.Text.Trim();
                    _productDto.v_SerialNumber = txtSerialNumber.Text.Trim();
                    //_productDto.d_ExpirationDate = string.IsNullOrEmpty(dtpExpirationDate.Text) ? (DateTime?)null : DateTime.Parse(dtpExpirationDate.Text);

                    if (dtpExpirationDate.Checked == false)
                    {
                        _productDto.d_ExpirationDate = null;
                    }
                    else
                    {
                        _productDto.d_ExpirationDate = dtpExpirationDate.Value;
                    }
                    _productDto.i_MeasurementUnitId     = Convert.ToInt32(ddlMeasurementUnitId.SelectedValue);
                    _productDto.r_ReferentialCostPrice  = string.IsNullOrEmpty(txtReferentialCostPrice.Text) ? (float?)null : float.Parse(txtReferentialCostPrice.Text);
                    _productDto.r_ReferentialSalesPrice = string.IsNullOrEmpty(txtReferentialSalesPrice.Text) ? (float?)null : float.Parse(txtReferentialSalesPrice.Text);
                    _productDto.v_Presentation          = txtPresentation.Text.Trim();
                    _productDto.v_AdditionalInformation = txtAdiccionalInformation.Text.Trim();

                    // Save the data
                    _objBL.AddProduct(ref objOperationResult, _productDto, Globals.ClientSession.GetAsList());
                }
                else if (_Mode == "Edit")
                {
                    _productDto.i_CategoryId   = Convert.ToInt32(ddlCategoryId.SelectedNode.Tag);
                    _productDto.v_Name         = txtName.Text.Trim();
                    _productDto.v_GenericName  = txtGenericName.Text.Trim();
                    _productDto.v_BarCode      = txtBarCode.Text.Trim();
                    _productDto.v_ProductCode  = txtBarCode.Text.Trim();
                    _productDto.v_Brand        = txtBrand.Text.Trim();
                    _productDto.v_Model        = txtModel.Text.Trim();
                    _productDto.v_SerialNumber = txtSerialNumber.Text.Trim();
                    if (dtpExpirationDate.Checked == false)
                    {
                        _productDto.d_ExpirationDate = null;
                    }
                    else
                    {
                        _productDto.d_ExpirationDate = dtpExpirationDate.Value;
                    }
                    //_productDto.d_ExpirationDate = string.IsNullOrEmpty(dtpExpirationDate.Text) ? (DateTime?)null : DateTime.Parse(dtpExpirationDate.Text);
                    _productDto.i_MeasurementUnitId     = Convert.ToInt32(ddlMeasurementUnitId.SelectedValue);
                    _productDto.r_ReferentialCostPrice  = string.IsNullOrEmpty(txtReferentialCostPrice.Text) ? (float?)null : float.Parse(txtReferentialCostPrice.Text);
                    _productDto.r_ReferentialSalesPrice = string.IsNullOrEmpty(txtReferentialSalesPrice.Text) ? (float?)null : float.Parse(txtReferentialSalesPrice.Text);
                    _productDto.v_Presentation          = txtPresentation.Text.Trim();
                    _productDto.v_AdditionalInformation = txtAdiccionalInformation.Text.Trim();

                    // Save the data
                    _objBL.UpdateProduct(ref objOperationResult, _productDto, Globals.ClientSession.GetAsList());
                }
                //// Analizar el resultado de la operación
                if (objOperationResult.Success == 1)  // Operación sin error
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                else  // Operación con error
                {
                    MessageBox.Show(Constants.GenericErrorMessage, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // Se queda en el formulario.
                }
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }