コード例 #1
0
        private int DeleteTransfer(TblTransferHeader row)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in context.TblTransferHeaders
                              where e.Iserial == row.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    context.DeleteObject(oldRow);
                }

                context.SaveChanges();
            }
            return(row.Iserial);
        }
コード例 #2
0
        public void SaveMainRow()
        {
            if (SelectedMainRow != null)
            {
                var valiationCollection = new List <ValidationResult>();

                var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true);
                isvalid &= UserWarehouseList.Any(uw =>
                                                 uw.WarehouseIserial == SelectedMainRow.WarehouseFrom ||
                                                 uw.WarehouseIserial == SelectedMainRow.WarehouseTo);
                if (isvalid)
                {
                    var saveRow = new TblTransferHeader()
                    {
                        DocDate        = DateTime.Now,
                        CreatedBy      = 1,
                        CreationDate   = DateTime.Now,
                        Approved       = false,
                        LastChangeDate = DateTime.Now,
                        CodeFrom       = "",
                        CodeTo         = "",
                    };
                    saveRow.InjectFrom(SelectedMainRow);
                    saveRow.TblTransferDetails = new ObservableCollection <TblTransferDetail>();
                    foreach (var item in SelectedMainRow.TblTransferDetails)
                    {
                        var detailTemp = new TblTransferDetail();
                        detailTemp.InjectFrom(item);
                        detailTemp.ItemTransfer = new Web.DataLayer.ItemDimensionSearchModel();
                        saveRow.TblTransferDetails.Add(detailTemp);
                    }

                    var mainRowIndex = MainRowList.IndexOf(SelectedMainRow);
                    if (mainRowIndex < 0)
                    {
                        MainRowList.Insert(mainRowIndex + 1, SelectedMainRow); mainRowIndex++;
                    }
                    WarehouseClient.UpdateOrInsertTransferHeaderAsync(saveRow, mainRowIndex, LoggedUserInfo.Iserial);
                }
                else
                {
                    MessageBox.Show("Please Choose one of your assigned warehouses");
                }
            }
        }
コード例 #3
0
        private TblTransferHeader UpdateOrInsertTransferHeader(TblTransferHeader newRow, int index, int userIserial, out int outindex)// )
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                try
                {
                    var oldRow = context.TblTransferHeaders.Include(nameof(TblTransferHeader.TblTransferDetails)).FirstOrDefault(th => th.Iserial == newRow.Iserial);
                    newRow.TblWarehouseFrom = null;
                    newRow.TblWarehouseTo   = null;
                    if (oldRow != null)// الهيدر موجود قبل كده
                    {
                        newRow.LastChangeUser = userIserial;
                        newRow.LastChangeDate = DateTime.Now;
                        if (!oldRow.Approved && newRow.Approved)// كده لسه معموله ابروف
                        {
                            var warehouseTo = context.TblWarehouses.FirstOrDefault(w => w.Iserial == newRow.WarehouseTo);
                            var seqTo       = warehouseTo.TransferIn;
                            var seqRow      = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == seqTo);
                            newRow.CodeTo      = SharedOperation.HandelSequence(seqRow);
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        //// هحذف الى اتحذف
                        //foreach (var item in oldRow.TblTransferDetails)
                        //{
                        //    if (!newRow.TblTransferDetails.Any(td => td.Iserial == item.Iserial))// مش موجود فى الجديد يبقى اتحذف
                        //        DeleteTransferDetail(item);
                        //}
                        foreach (var item in newRow.TblTransferDetails.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp, headeriserial;//item.ItemTransfer
                            headeriserial          = item.TransferHeader;
                            item.TblTransferHeader = null;
                            item.TransferHeader    = headeriserial;
                            UpdateOrInsertTransferDetail(item, 1, out temp);
                            item.TblTransferHeader = newRow;
                        }
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                        SharedOperation.GenericUpdate(oldRow, newRow, context);
                    }
                    else// الهيدر ده جديد
                    {
                        var warehouseFrom = context.TblWarehouses.FirstOrDefault(w => w.Iserial == newRow.WarehouseFrom);
                        var seq           = warehouseFrom.TransferOut;
                        var seqRow        = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == seq);
                        newRow.CodeFrom = SharedOperation.HandelSequence(seqRow);
                        if (newRow.Approved)// كده معموله ابروف
                        {
                            var warehouseTo = context.TblWarehouses.FirstOrDefault(w => w.Iserial == newRow.WarehouseTo);
                            var seqTo       = warehouseTo.TransferIn;
                            var seqRowTo    = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == seqTo);
                            newRow.CodeTo      = SharedOperation.HandelSequence(seqRowTo);
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        else
                        {
                            newRow.CodeTo = newRow.CodeFrom;
                        }
                        newRow.CreatedBy      = userIserial;
                        newRow.CreationDate   = DateTime.Now;
                        newRow.LastChangeDate = DateTime.Now;
                        newRow.LastChangeUser = userIserial;

                        context.TblTransferHeaders.AddObject(newRow);
                    }
                    context.SaveChanges();
                    foreach (var item in newRow.TblTransferDetails)
                    {
                        GetTransferItemDetails(context, item);
                    }
                }
                catch (Exception ex) { throw ex; }
                return(newRow);
            }
        }