コード例 #1
0
        public IHttpActionResult XmlWrite(string documentType, int id)
        {
            XmlCountPlan countPlan = new XmlCountPlan();
            bool         result    = false;

            switch (documentType.ToUpper())
            {
            case "COUNTPLAN":

                result = countPlan.Create(id);

                break;

            case "RECEPTION":
                break;

            default:
                return(NotFound());
            }
            return(Ok(result));
        }
コード例 #2
0
        public bool Update(CountPlan items)
        {
            try
            {
                //var _lote = items.Value3; //Lote
                XmlCountPlan xml         = new XmlCountPlan();
                var          plan        = new CountPlan();
                var          planDetails = new CountPlanDetail();

                if (items == null)
                {
                    return(false);
                }

                int planId = items.Id;

                bool createNewPlan = Convert.ToBoolean(items.Value2); //este campo es asignado true/false si hay
                //que crear un nuevo plan cuando el porcentaje es mayor a 3%

                var existingCount = context.CountPlans.First(a => a.Id == items.Id);


                if (existingCount != null)
                {
                    //UPDATE PLAN
                    var planName        = existingCount.Name;
                    var planDescription = existingCount.Description;
                    var warehouse       = existingCount.Warehouse;
                    existingCount.Status = "0";
                    //existingCount.Value3 = _lote;
                    existingCount.UserUpdated = items.UserUpdated;
                    existingCount.DateUpdated = DateTime.Now.ToString("dd/MM/yyyy hh:mm");

                    context.Entry(existingCount).State = EntityState.Modified;
                    context.SaveChanges();
                    //UPDATE PLAN


                    #region "CREATE NUEVO PLAN"


                    if (createNewPlan) //crea plan con productos no contados
                    {
                        var lastOrDefault = context.CountPlans.OrderByDescending(a => a.Id).Select(a => a.Id).First();
                        if (lastOrDefault != null)
                        {
                            //int lastPlan = lastOrDefault + 1;
                            plan.Warehouse   = warehouse;
                            plan.Name        = "Plan Conteo " + planName;
                            plan.Description = "Productos no contados, " + planDescription;
                            plan.Status      = "2";
                            plan.DateCreated = DateTime.Now.ToString("dd/MM/yyyy hh:mm");

                            context.CountPlans.Add(plan);
                            context.SaveChanges();

                            int newPlanId = plan.Id;



                            //        //CODIGO NUEVO 14-1017
                            var qry = "SELECT CPD.Id AS Id,";
                            qry += "CP.Id AS IdCountPlan,";
                            qry += "CP.Name,";
                            qry += "CP.Description,";
                            qry += "CPD.ProductCode,";
                            qry += "CPD.Quantity,";
                            qry += "CPD.TotalCounted,";
                            qry += "P.Barcode,";
                            qry += "P.Description AS ProductDescription,";
                            qry +=
                                "CASE  WHEN SUM(CPDI.Quantity) > 0 THEN  SUM(CPDI.Quantity) ELSE 0 END AS TotalProduct,";
                            qry += "CP.Warehouse ";
                            qry += " FROM CountPlan CP INNER JOIN";
                            qry += " CountPlanDetail CPD ON  CP.Id = CPD.CountPlanId INNER JOIN";
                            qry += " Product P ON CPD.ProductCode = P.Code LEFT OUTER JOIN";
                            qry +=
                                " CountPlanDetailItem CPDI ON ((CPD.CountPlanId = CPDI.CountPlanId) AND (P.Code = CPDI.ProductCode ))";
                            qry += " WHERE CP.Id = '" + planId + "' ";
                            qry +=
                                " GROUP BY CP.Id, CP.Name, CP.Description, CPD.ProductCode, CPD.Quantity,  CPD.TotalCounted, P.Barcode, P.Description";

                            var details = context.Database.SqlQuery <ViewCountPlanDetail>(qry).ToList();
                            //FIN NUEVO 14-1017


                            //var details = context.CountPlanDetailExtends.Where(a => a.IdCountPlan == planId).ToList();

                            if (details != null)
                            {
                                foreach (var row in details)
                                {
                                    planDetails.CountPlanId   = newPlanId;
                                    planDetails.ProductCode   = row.ProductCode;
                                    planDetails.Quantity      = row.Quantity - row.TotalProduct;
                                    planDetails.DateCreated   = DateTime.Now.ToString("dd/MM/yyyy hh:mm");
                                    planDetails.UserIdCreated = 0;
                                    if (planDetails.Quantity > 0)
                                    {
                                        context.CountPlanDetails.Add(planDetails);
                                        context.SaveChanges();
                                    }
                                }
                            }
                        }
                    }

                    #endregion

                    bool result = xml.Create(planId); //Crea XML
                }
                else
                {
                    return(false);
                }


                return(true);
            }
            catch (Exception ex)
            {
                Debug.Write("Error " + ex.Message);
                return(false);
            }
        }