public async Task <RctExtendModel> Add(RctExtendModel model)
        {
            var    _rct = new RctExtendModel();
            string url  = "http://" + PATHSERVER + "/tshirt/Order/PostRct";

            try
            {
                var json    = JsonConvert.SerializeObject(model);
                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();

                    _rct = JsonConvert.DeserializeObject <RctExtendModel>(x);
                }
            }
            catch (Exception ex)
            {
                _rct = null;
                //Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
            return(_rct);
        }
Exemplo n.º 2
0
        //private OrderService orderService;
        //private RctServices rctServices;

        public RctViewModel(string providerName, RctExtendModel rct)
        {
            //Codes = "OC " + codes;
            ProviderName = providerName;
            Lot          = rct.Lot;
            RctCode      = rct.Code; //  "RCT" + rct.Id;
            InitializeView(rct.Details);

            int height = (40 * Orders.Count) + (5 * Orders.Count);

            HeightList = height.ToString();
        }
Exemplo n.º 3
0
 public HttpResponseMessage PostRct(RctExtendModel rct)
 {
     if (rct != null)
     {
         var result = _rctRepository.Add(rct);
         return(Request.CreateResponse(HttpStatusCode.OK, result));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
Exemplo n.º 4
0
        private async void Save()
        {
            var rct = new RctExtendModel();

            var answer = await App.Current.MainPage.DisplayAlert("TSHIRT", "Esta seguro que desea Guardar?", "SI", "NO");

            if (answer)
            {
                var result = await countServices.SaveDetail(NewDetails.ToList());

                if (result == "OK")
                {
                    Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new Plan(PlanId));
                }
                else
                {
                    App.Current.MainPage.DisplayAlert("TSHIRT - Error", result, "OK");
                }
            }
        }
Exemplo n.º 5
0
        private async void Save()
        {
            var rct = new RctExtendModel();

            if (ValidateOrder())
            {
                var answer = await App.Current.MainPage.DisplayAlert("TSHIRT", "Esta seguro que desea Guardar?", "SI", "NO");

                if (answer)
                {
                    //var _details = OrderProduct.Select(items => new Detail()
                    //{
                    //    OrderCode = items
                    //}).Distinct().ToList();

                    var _details = Orders.Where(a => a.TotalProduct > 0).Select(items => new Detail()
                    {
                        OrderCode   = items.Code,
                        Status      = (items.Quantity > items.TotalProduct) ? Open.ToString() : Close.ToString(),
                        ProductCode = items.ProductCode,
                        Warehouse   = items.OrderValue1,
                        Quantity    = items.TotalProduct
                    }).ToList();



                    rct.Lot          = Lote;
                    rct.ProviderCode = ProviderCode;
                    rct.UserId       = 1;
                    rct.Details      = _details;

                    var result = await rctServices.Add(rct);

                    if (result != null)
                    {
                        await Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new Rct(ProviderName, result));
                    }
                }
            }
        }
Exemplo n.º 6
0
        //public bool SaveOrderAndGenerateXML(string code)
        public RctExtendModel SaveOrderAndGenerateXML(RctExtendModel rct)
        {
            bool         result     = true;
            int          lastDetail = 0;
            XmlReception xml        = new XmlReception();
            var          list       = new List <Detail>();
            Rct          _rct       = new Rct();

            try
            {
                _rct.Lot = rct.Lot;

                string[] arrayCode = rct.Details.Select(a => a.OrderCode).Distinct().ToArray();

                //obtiene el Status del ultimo registro
                var orderDetailProduct = context.OrderDetailProducts.Where(a => arrayCode.Contains(a.OrderCode) && a.Status == 0).ToList();

                if (orderDetailProduct.Count > 0)
                {
                    lastDetail = orderDetailProduct.Max(b => b.Status) + 1;
                    var getforUpdate = orderDetailProduct.Where(a => a.Status == 0);


                    foreach (var items in rct.Details)
                    {
                        var getQry = context.OrderDetails.FirstOrDefault(b => b.OrderCode == items.OrderCode && b.ProductCode == items.ProductCode);
                        if (getQry != null)
                        {
                            getQry.Quantity             = (items.Quantity <= getQry.Quantity) ? (getQry.Quantity - items.Quantity) : 0;
                            getQry.Value1               = items.Warehouse;
                            context.Entry(getQry).State = EntityState.Modified;
                        }
                    }

                    context.SaveChanges();


                    foreach (var detail in arrayCode)
                    {
                        string _status = "Abierta";

                        var statusOrder = context.OrderDetails.Any(a => a.OrderCode == detail && a.Quantity > 1);
                        if (!statusOrder)
                        {
                            _status = "Cerrada";
                            //bool updateOrder = UpdateOrderStatus(detail, "1");
                        }

                        list.Add(new Detail()
                        {
                            OrderCode = detail, Status = _status
                        });


                        var orders = context.Orders.FirstOrDefault(a => a.Code == detail);
                        orders.Value1 = (_status == "Cerrada") ? "1" : "0";
                        orders.Value2 = rct.Lot;

                        context.Entry(orders).State = EntityState.Modified;
                        context.SaveChanges();
                    }



                    string createXML = xml.Create(arrayCode); //Crea XML

                    if (createXML != "ERROR")
                    {
                        var qry = "UPDATE ";
                        qry += " OrderDetailProduct";
                        qry += " SET";
                        qry += " Status = '1'";
                        qry += " WHERE OrderCode IN ('" + String.Join("','", arrayCode) + "') AND Status ='0'";
                        var list2 = context.Database.ExecuteSqlCommand(qry); //.SqlQuery<OrderDetailProduct>(qry);


                        rct.Code        = createXML;
                        rct.DateCreated = DateTime.Now.ToString("dd/MM/yyyy");
                        rct.Details     = list;
                    }
                    else
                    {
                        rct = null;
                    }
                }
            }
            catch (Exception ex)
            {
                rct.Code = ex.Message;
            }
            return(rct);
        }
        public RctExtendModel Add(RctExtendModel rct)
        {
            try
            {
                Rct       _rct    = new Rct();
                RctDetail _detail = new RctDetail();
                var       _date   = DateTime.Now.ToString("dd/MM/yyyy/hh:mm");
                var       _lote   = rct.Lot;

                _rct.Lot          = _lote;
                _rct.DateCreated  = _date;
                _rct.ProviderCode = rct.ProviderCode;
                _rct.UserId       = rct.UserId;

                var addRct = context.Rcts.Add(_rct);
                var result = context.SaveChanges();

                int rctId = addRct.Id;


                //add warehouse to OrderDetail
                foreach (var item in rct.Details)
                {
                    bool updateOrderDetail = _order.UpdateOrderDetail(item.OrderCode, item.ProductCode, item.Warehouse);
                }

                var list = new List <Detail>();
                //add RctDetail
                foreach (var detail in rct.Details.Select(a => a.OrderCode).Distinct().ToList())
                {
                    string _status = "Abierta";
                    _detail.RctId     = rctId;
                    _detail.OrderCode = detail;
                    context.RctDetails.Add(_detail);
                    context.SaveChanges();


                    //UPDATE STATUS ORDER
                    var statusOrder = rct.Details.Any(a => a.OrderCode == detail && a.Status == "0");
                    if (!statusOrder)
                    {
                        _status = "Cerrada";
                        bool updateOrder = _order.UpdateOrderStatus(detail, "1");
                    }

                    list.Add(new Detail()
                    {
                        OrderCode = detail, Status = _status
                    });
                }



                //UPDATE ORDER LOTE
                var ordersGroup = rct.Details.GroupBy(a => a.OrderCode)
                                  .Select(grp => grp.First())
                                  .ToList();

                foreach (var item in ordersGroup)
                {
                    var _orders = context.Orders.FirstOrDefault(a => a.Code == item.OrderCode);
                    _orders.Value2 = _lote;

                    context.Entry(_orders).State = EntityState.Modified;
                    context.SaveChanges();
                }



                rct.Id          = rctId;
                rct.DateCreated = _date;
                rct.Details     = list;

                return(rct);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public Rct(string ordercode, RctExtendModel rct)
 {
     InitializeComponent();
     BindingContext = new RctViewModel(ordercode, rct);
 }