コード例 #1
0
        public void DeleteDetail(int id)
        {
            UnloadDetail newUnloadCylinder = context.UnloadDetails.Where(obj => obj.ID == id).FirstOrDefault();
            var          t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == newUnloadCylinder.cylinder_Id);
            var          livecylinder = t.First();

            if (t != null)
            {
                var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) - newUnloadCylinder.FilledCylinder;
                if (fillecount <= 0)
                {
                    livecylinder.FilledCylinderCount = 0;
                }
                else
                {
                    livecylinder.FilledCylinderCount = fillecount;
                }


                var emptycount = Convert.ToInt32(livecylinder.EmptyCylinderCount) - newUnloadCylinder.EmptyCylinder;
                if (emptycount <= 0)
                {
                    livecylinder.EmptyCylinderCount = 0;
                }
                else
                {
                    livecylinder.EmptyCylinderCount = emptycount;
                }

                var replacecount = Convert.ToInt32(livecylinder.ReplacementCylinderCount) - newUnloadCylinder.RejectedCylinder;
                if (replacecount <= 0)
                {
                    livecylinder.ReplacementCylinderCount = 0;
                }
                else
                {
                    livecylinder.ReplacementCylinderCount = replacecount;
                }
                context.SaveChanges();
            }

            context.UnloadDetails.Remove(newUnloadCylinder);
            context.SaveChanges();
        }
コード例 #2
0
        public int Insert(UnloadCylinder obj)
        {
            UnloadCylinder newUnloadCylinder = new UnloadCylinder();


            newUnloadCylinder.UnloadDetail  = obj.UnloadDetail;
            newUnloadCylinder.user_id       = obj.user_id;
            newUnloadCylinder.userName      = obj.userName;
            newUnloadCylinder.UnloadDate    = obj.UnloadDate;
            newUnloadCylinder.EmptyCylinder = obj.EmptyCylinder;
            newUnloadCylinder.createdBy     = obj.createdBy;
            newUnloadCylinder.createdOn     = obj.createdOn;
            context.UnloadCylinders.Add(newUnloadCylinder);
            context.SaveChanges();
            if (obj.UnloadDetail != null)
            {
                foreach (var i in obj.UnloadDetail)
                {
                    UnloadDetail newUnloadDetail = new UnloadDetail();
                    newUnloadDetail.cylinder_Id      = i.cylinder_Id;
                    newUnloadDetail.cylinderType     = i.cylinderType;
                    newUnloadDetail.EmptyCylinder    = i.EmptyCylinder;
                    newUnloadDetail.FilledCylinder   = i.FilledCylinder;
                    newUnloadDetail.RejectedCylinder = i.RejectedCylinder;
                    var t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id);
                    var livecylinder = t.First();
                    if (t != null)
                    {
                        var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) + i.FilledCylinder;
                        if (fillecount <= 0)
                        {
                            livecylinder.FilledCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.FilledCylinderCount = fillecount;
                        }


                        var emptycount = Convert.ToInt32(livecylinder.EmptyCylinderCount) + i.EmptyCylinder;
                        if (emptycount <= 0)
                        {
                            livecylinder.EmptyCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.EmptyCylinderCount = emptycount;
                        }

                        var replacecount = Convert.ToInt32(livecylinder.ReplacementCylinderCount) + i.RejectedCylinder;
                        if (replacecount <= 0)
                        {
                            livecylinder.ReplacementCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.ReplacementCylinderCount = replacecount;
                        }
                        context.SaveChanges();
                    }
                    newUnloadDetail.unload_Id = newUnloadCylinder.ID;
                    context.UnloadDetails.Add(newUnloadDetail);


                    var deliverycount = (
                        from delivery in context.DeliveryDetails
                        where delivery.userid == obj.user_id && delivery.C_deliveryDate == obj.UnloadDate &&
                        delivery.unload_Flag == false
                        select delivery
                        ).FirstOrDefault();
                    if (deliverycount != null)
                    {
                        deliverycount.unload_Flag = true;
                        context.SaveChanges();
                    }
                }
            }
            return(newUnloadCylinder.ID);
        }
コード例 #3
0
        public void Update(UnloadCylinder obj)
        {
            UnloadCylinder newUnloadCylinder = context.UnloadCylinders.Where(obj1 => obj1.ID == obj.ID).FirstOrDefault();

            newUnloadCylinder.user_id       = obj.user_id;
            newUnloadCylinder.userName      = obj.userName;
            newUnloadCylinder.UnloadDate    = obj.UnloadDate;
            newUnloadCylinder.EmptyCylinder = obj.EmptyCylinder;
            context.SaveChanges();

            if (obj.UnloadDetailForEdit != null)
            {
                foreach (var i in obj.UnloadDetailForEdit)
                {
                    UnloadDetail newUnloadDetail = new UnloadDetail();

                    newUnloadDetail.cylinder_Id      = i.cylinder_Id;
                    newUnloadDetail.cylinderType     = i.cylinderType;
                    newUnloadDetail.EmptyCylinder    = i.EmptyCylinder;
                    newUnloadDetail.FilledCylinder   = i.FilledCylinder;
                    newUnloadDetail.RejectedCylinder = i.RejectedCylinder;
                    var t            = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id);
                    var livecylinder = t.First();
                    if (t != null && i.ID <= 0)
                    {
                        var fillecount = Convert.ToInt32(livecylinder.FilledCylinderCount) + i.FilledCylinder;
                        if (fillecount <= 0)
                        {
                            livecylinder.FilledCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.FilledCylinderCount = fillecount;
                        }


                        var emptycount = Convert.ToInt32(livecylinder.EmptyCylinderCount) + i.EmptyCylinder;
                        if (emptycount <= 0)
                        {
                            livecylinder.EmptyCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.EmptyCylinderCount = emptycount;
                        }

                        var replacecount = Convert.ToInt32(livecylinder.ReplacementCylinderCount) + i.RejectedCylinder;
                        if (replacecount <= 0)
                        {
                            livecylinder.ReplacementCylinderCount = 0;
                        }
                        else
                        {
                            livecylinder.ReplacementCylinderCount = replacecount;
                        }
                        context.SaveChanges();
                    }
                    //var livecylinder = context.LiveCylinderDetails.Where(c => c.cylinder_Id == i.cylinder_Id).FirstOrDefault();
                    //if (livecylinder.FilledCylinderCount == null) { livecylinder.FilledCylinderCount = 0; }
                    //if (livecylinder.EmptyCylinderCount == null) { livecylinder.EmptyCylinderCount = 0; }
                    //if (livecylinder.ReplacementCylinderCount == null) { livecylinder.ReplacementCylinderCount = 0; }
                    //if (livecylinder != null)
                    //{
                    //    livecylinder.FilledCylinderCount = livecylinder.FilledCylinderCount + i.FilledCylinder;
                    //    livecylinder.EmptyCylinderCount = livecylinder.EmptyCylinderCount + i.EmptyCylinder;
                    //    livecylinder.ReplacementCylinderCount = livecylinder.ReplacementCylinderCount + i.RejectedCylinder;
                    //    context.SaveChanges();
                    //}
                    //else
                    //{
                    //    var livecylinderNew = new LiveCylinderDetail();
                    //    livecylinderNew.cylinder_Id = i.cylinder_Id;
                    //    livecylinderNew.CylinderTypeName = i.cylinderType;
                    //    livecylinderNew.FilledCylinderCount = i.FilledCylinder;
                    //    livecylinderNew.EmptyCylinderCount = i.EmptyCylinder;
                    //    livecylinderNew.ReplacementCylinderCount = i.RejectedCylinder;
                    //    context.LiveCylinderDetails.Add(livecylinderNew);
                    //    context.SaveChanges();
                    //}
                    newUnloadDetail.unload_Id = obj.ID;
                    context.UnloadDetails.Add(newUnloadDetail);
                    context.SaveChanges();
                }
            }
        }