public async Task <bool> SaveCountPlan(CountPlan item)
        {
            bool   plan = true;
            string url  = "http://" + PATHSERVER + "/tshirt/Count/SavePlan";

            try
            {
                var json    = JsonConvert.SerializeObject(item);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage result = null;

                result = await client.PostAsync(url, content);

                if (result.IsSuccessStatusCode)
                {
                    var x = await result.Content.ReadAsStringAsync();

                    plan = JsonConvert.DeserializeObject <bool>(x);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
            return(plan);
        }
        public async void Save()
        {
            var  _plan = new CountPlan();
            bool result;

            // _plan.Value3 = Lote;   //value2 field used to Lote
            _plan.Id = Details.Select(a => a.IdCountPlan).FirstOrDefault();



            if (EstatusPlanConteo == (int)EnumTShirt.CountEstatus.SINDIFERENCIA)
            {
                _plan.Value2 = false.ToString();
                var answer = await App.Current.MainPage.DisplayAlert("TSHIRT", "Desea Guardar el Plan de Conteo", "SI", "NO");

                if (answer)
                {
                    EnableButton();
                    result = await countServices.SaveCountPlan(_plan);

                    if (result)
                    {
                        await Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new PlanList(User));
                    }
                }
            }
            else if (EstatusPlanConteo == (int)EnumTShirt.CountEstatus.DIFERENCIAMEDIA)
            {
                _plan.Value2 = false.ToString();
                var answer = await App.Current.MainPage.DisplayAlert("TSHIRT", "Diferencia MENOR al " + Porcentaje + "%, Desea Continuar?", "SI", "NO");

                if (answer)
                {
                    EnableButton();
                    result = await countServices.SaveCountPlan(_plan);

                    if (result)
                    {
                        await Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new PlanList(User));
                    }
                }
            }
            else
            {
                _plan.Value2 = true.ToString();
                var answer = await App.Current.MainPage.DisplayAlert("TSHIRT", "Diferencia MAYOR al " + Porcentaje + "%, Desea Continuar?", "SI", "NO");

                if (answer)
                {
                    EnableButton();
                    result = await countServices.SaveCountPlan(_plan);

                    if (result)
                    {
                        await Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new PlanList(User));
                    }
                }
            }
        }
        public async Task <bool> SaveCountPlan(CountPlan item)
        {
            bool result = false;

            try
            {
                CountPlanRepository _repository = App.CountPlanRepo;
                bool flag = await _repository.UpdatePlan(item);

                result      = flag;
                _repository = (CountPlanRepository)null;
            }
            catch (Exception ex1)
            {
                Exception ex = ex1;
                result = false;
                throw;
            }
            return(result);
        }
 public bool SavePlan(CountPlan items)
 {
     return(_countRepository.Update(items));
 }
Example #5
0
 public bool Update(CountPlan items)
 {
     return(repository.Update(items));
 }
Example #6
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);
            }
        }