コード例 #1
0
        private List <TblStoreCommission> UpdateOrInsertStoreCommission(List <TblStoreCommission> newRows, string company)// int index, out int outindex,
        {
            //outindex = index;
            using (var context = new ccnewEntities(service.GetSqlConnectionString(company)))
            {
                try
                {
                    foreach (var item in newRows)
                    {
                        var oldRow = context.TblStoreCommissions.FirstOrDefault(th => th.Tblstore == item.Tblstore);

                        if (oldRow != null)
                        {
                            SharedOperation.GenericUpdate(oldRow, item, context);
                        }
                        else
                        {
                            item.TblStore1 = null;
                            context.TblStoreCommissions.AddObject(item);
                        }

                        context.SaveChanges();
                    }
                }
                catch (Exception ex) { throw Helper.GetInnerException(ex); }
                return(newRows);
            }
        }
コード例 #2
0
        private List <TblPurchaseOrderHeaderRequestPayment> UpdateOrInsertTblPurchaseOrderHeaderRequestPayments(List <TblPurchaseOrderHeaderRequestPayment> ListToSave)
        {
            using (var entity = new WorkFlowManagerDBEntities())
            {
                foreach (var newRow in ListToSave)
                {
                    if (newRow.Iserial == 0)
                    {
                        entity.TblPurchaseOrderHeaderRequestPayments.AddObject(newRow);
                    }
                    else
                    {
                        var oldRow = (from e in entity.TblPurchaseOrderHeaderRequestPayments
                                      where e.Iserial == newRow.Iserial
                                      select e).SingleOrDefault();
                        if (oldRow != null)
                        {
                            SharedOperation.GenericUpdate(oldRow, newRow, entity);
                        }
                    }
                }

                entity.SaveChanges();
                return(ListToSave);
            }
        }
コード例 #3
0
ファイル: PurchaseOrderRequest.cs プロジェクト: Osama91/CCWFM
        private TblPurchaseOrderHeaderRequest UpdateOrInsertTblPurchaseOrderHeaderRequest(TblPurchaseOrderHeaderRequest newRow, int index, int user, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                var warehouse = context.TblWarehouses.FirstOrDefault(w => w.Iserial == newRow.TblWarehouse).Po;

                var seq = context.TblSequenceProductions.FirstOrDefault(w => w.Iserial == warehouse);

                var oldRow = (from e in context.TblPurchaseOrderHeaderRequests
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    newRow.CreatedBy    = oldRow.CreatedBy;
                    newRow.CreationDate = oldRow.CreationDate;
                    SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    newRow.CreationDate = DateTime.Now;
                    newRow.CreatedBy    = user;
                    newRow.Code         = SharedOperation.HandelSequence(seq);
                    context.TblPurchaseOrderHeaderRequests.AddObject(newRow);
                }
                context.SaveChanges();

                return(newRow);
            }
        }
コード例 #4
0
ファイル: UsersApprovalStatus.cs プロジェクト: Osama91/CCWFM
 private TblUsersApprovalStatu UpdateOrInsertTblUsersApprovalStatus(TblUsersApprovalStatu newRow, bool save, int index, int user, out int outindex)
 {
     outindex = index;
     try
     {
         using (var context = new WorkFlowManagerDBEntities())
         {
             if (save)
             {
                 context.TblUsersApprovalStatus.AddObject(newRow);
             }
             else
             {
                 var oldRow = (from e in context.TblUsersApprovalStatus
                               where e.Iserial == newRow.Iserial
                               select e).SingleOrDefault();
                 if (oldRow != null)
                 {
                     SharedOperation.GenericUpdate(oldRow, newRow, context);
                 }
             }
             context.SaveChanges();
         }
         return(newRow);
     }
     catch (Exception)
     {
         return(newRow);
     }
 }
コード例 #5
0
        private TblAdjustmentTempDetail UpdateOrInsertAdjustmentTempDetail(TblAdjustmentTempDetail newRow, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                try
                {
                    var oldRow = (from e in context.TblAdjustmentTempDetails
                                  where e.Iserial == newRow.Iserial
                                  select e).SingleOrDefault();
                    if (oldRow != null)
                    {
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                        SharedOperation.GenericUpdate(oldRow, newRow, context);
                    }
                    else
                    {
                        context.TblAdjustmentTempDetails.AddObject(newRow);
                    }

                    context.SaveChanges();
                }
                catch (Exception ex) { }
                return(newRow);
            }
        }
コード例 #6
0
ファイル: StyleTNAApproval.cs プロジェクト: Osama91/CCWFM
        private TblStyleTNAStatusDetail UpdateOrInsertTblStyleTNAStatusDetail(TblStyleTNAStatusDetail newRow, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                //   context.Connection.ConnectionTimeout = 0;
                var oldRow = (from e in context.TblStyleTNAStatusDetails
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    context.TblStyleTNAStatusDetails.AddObject(newRow);
                }
                var styleTNA = context.TblStyleTNAHeaders.Include(nameof(TblStyleTNAHeader.TblStyle1)).Include(nameof(TblStyleTNAHeader.TblStyleTNAColorDetails)).FirstOrDefault(x => x.Iserial == newRow.TblStyleTNAHeader);
                styleTNA.TblStyleTNAStatus = newRow.TblStyleTnaStatus;
                if (styleTNA.TblStyleTNAStatus == 1)
                {
                    GenerateSalesOrderFromTna(styleTNA);
                }
                context.SaveChanges();

                return(newRow);
            }
        }
コード例 #7
0
ファイル: MarkUp.cs プロジェクト: Osama91/CCWFM
        private TblDyeingOrderInvoiceMarkupTransProd UpdateOrInsertDyeingOrderInvoiceMarkupTransProds(TblDyeingOrderInvoiceMarkupTransProd newRow, bool save, int index, out int outindex, string company)
        {
            outindex = index;
            using (var entity = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var entityrow = entity.Entities.Any(w => w.Iserial == newRow.TblMarkupProd && w.scope == 0 && w.TblJournalAccountType == 9 && w.AccountIserial != 0);

                if (!entityrow)
                {
                    newRow.Iserial = -1;
                    return(newRow);
                }
            }
            using (var entity = new WorkFlowManagerDBEntities())
            {
                newRow.TblMarkupProd1 = null;
                if (save)
                {
                    entity.TblDyeingOrderInvoiceMarkupTransProds.AddObject(newRow);
                }
                else
                {
                    var oldRow = (from e in entity.TblDyeingOrderInvoiceMarkupTransProds
                                  where e.Iserial == newRow.Iserial
                                  select e).SingleOrDefault();
                    if (oldRow != null)
                    {
                        SharedOperation.GenericUpdate(oldRow, newRow, entity);
                    }
                }
                entity.SaveChanges();
                return(newRow);
            }
        }
コード例 #8
0
ファイル: ContractService.svc.cs プロジェクト: Osama91/CCWFM
        private TblContractPaymentByPeriod UpdateOrInsertContractPaymentDetail(
            TblContractPaymentByPeriod newRow, int userIserial, int index, out int outindex)
        {
            outindex = index;
            newRow.TblContractHeader1 = null;
            using (var context = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in context.TblContractPaymentByPeriods
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                    var result = SharedOperation.GenericUpdate(oldRow, newRow, context);
                    if (result.Count() > 0)
                    {
                        oldRow.LastChangeDate = DateTime.Now;
                        oldRow.LastChangeUser = userIserial;
                    }
                }
                else
                {
                    newRow.CreatedBy      = userIserial;
                    newRow.LastChangeUser = userIserial;
                    newRow.CreationDate   = DateTime.Now;
                    newRow.LastChangeDate = DateTime.Now;
                    context.TblContractPaymentByPeriods.AddObject(newRow);
                }

                context.SaveChanges();
                return(newRow);
            }
        }
コード例 #9
0
 private TblDyeingOrderInvoiceHeader UpdateOrInsertDyeingOrderInvoiceHeader(TblDyeingOrderInvoiceHeader newRow, bool save, int index, out int outindex)
 {
     outindex = index;
     using (var context = new WorkFlowManagerDBEntities())
     {
         if (save)
         {
             var seqCode = SharedOperation.GetChainSetup("GlDyeingPostSequence");
             var seqProd = context.TblSequenceProductions.FirstOrDefault(w => w.Code == seqCode);
             newRow.Code = SharedOperation.HandelSequence(seqProd);
             context.TblDyeingOrderInvoiceHeaders.AddObject(newRow);
         }
         else
         {
             var oldRow = (from e in context.TblDyeingOrderInvoiceHeaders
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 SharedOperation.GenericUpdate(oldRow, newRow, context);
             }
         }
         context.SaveChanges();
         return(newRow);
     }
 }
コード例 #10
0
ファイル: TechPack.cs プロジェクト: Osama91/CCWFM
 public tblTechPackHeader InsertOrUpdateTBLTechPackHeader(tblTechPackHeader newRow)
 {
     using (var context = new WorkFlowManagerDBEntities())
     {
         var oldRow = (from e in context.tblTechPackHeaders
                       where e.Iserial == newRow.Iserial
                       select e).SingleOrDefault();
         if (oldRow != null)
         {
             SharedOperation.GenericUpdate(oldRow, newRow, context);
         }
         else
         {
             context.tblTechPackHeaders.AddObject(newRow);
         }
         context.SaveChanges();
         return(newRow);
     }
 }
コード例 #11
0
ファイル: ItemDimension.cs プロジェクト: Osama91/CCWFM
 private TblItemDim UpdateOrInsertItemDimension(TblItemDim newRow, int index, out int outindex)
 {
     outindex = index;
     using (var context = new WorkFlowManagerDBEntities())
     {
         var oldRow = (from e in context.TblItemDims
                       where e.Iserial == newRow.Iserial
                       select e).SingleOrDefault();
         if (oldRow != null)
         {
             //context.Entry(oldRow).CurrentValues.SetValues(newRow);
             SharedOperation.GenericUpdate(oldRow, newRow, context);
         }
         else
         {
             context.TblItemDims.AddObject(newRow);
         }
         context.SaveChanges();
         return(newRow);
     }
 }
コード例 #12
0
 private List <TblAttachment> UpdateOrInsertAttachment(List <TblAttachment> attachments,
                                                       out List <Tuple <int, string> > attachmentPath, out string FolderPath)
 {
     attachmentPath = new List <Tuple <int, string> >();
     using (var context = new WorkFlowManagerDBEntities())
     {
         var relativePath = context.tblChainSetups.FirstOrDefault(x => x.sGlobalSettingCode == "AttachmentsDefaultFolderPath").sSetupValue;
         FolderPath = relativePath;
         var v = GetPath(context);
         foreach (var newRow in attachments)
         {
             if (newRow.Iserial == 0)
             {
                 newRow.CreationDate = DateTime.Now;
                 newRow.FileName     = Guid.NewGuid() + Path.GetExtension(newRow.OrginalFileName);
                 newRow.Path         = "/Uploads/" + relativePath + "/" + newRow.FileName;
                 attachmentPath.Add(new Tuple <int, string>(v, newRow.Path));
                 context.TblAttachments.AddObject(newRow);
             }
             else
             {
                 var oldRow = (from e in context.TblAttachments
                               where e.Iserial == newRow.Iserial
                               select e).SingleOrDefault();
                 if (oldRow != null)
                 {
                     var changedItems = SharedOperation.GenericUpdate(oldRow, newRow, context);
                     if (changedItems.Count() > 1)
                     {
                         newRow.LastUpdatedDate = DateTime.Now;
                         attachmentPath.Add(new Tuple <int, string>(oldRow.Iserial, relativePath + oldRow.FileName));
                         SharedOperation.GenericUpdate(oldRow, newRow, context);
                     }
                 }
             }
         }
         context.SaveChanges();
         return(attachments);
     }
 }
コード例 #13
0
        public TblAuthUser SaveUser(TblAuthUser newRow, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                if (newRow.Iserial != 0)
                {
                    var oldRow = (from s in context.TblAuthUsers
                                  where s.Iserial == newRow.Iserial
                                  select s).SingleOrDefault();
                    if (oldRow != null)
                    {
                        SharedOperation.GenericUpdate(oldRow, newRow, context);
                    }
                }

                try
                {
                    if (newRow.Iserial == 0)
                    {
                        context.TblAuthUsers.AddObject(newRow);
                        context.SaveChanges();
                        context.TblUserExpiries.AddObject(new TblUserExpiry()
                        {
                            Tbluser        = newRow.Iserial,
                            LastChangeDate = DateTime.Now,
                            LastPass       = newRow.UserPassword
                        });
                    }

                    context.SaveChanges();
                }
                catch
                {
                    newRow.Ename = "ERROR_OCCURED";
                    newRow.Aname = "ERROR_OCCURED";
                }
                return(newRow);
            }
        }
コード例 #14
0
ファイル: SalaryApproval.cs プロジェクト: Osama91/CCWFM
        private TblSalaryApprovalDetail UpdateOrInsertSalaryApprovalDetail(
            TblSalaryApprovalDetail newRow, int userIserial, int index, out int outindex, string company)
        {
            outindex = index;
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var oldRow = (from e in context.TblSalaryApprovalDetails
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    var result = SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    context.TblSalaryApprovalDetails.AddObject(newRow);
                }

                context.SaveChanges();
                return(newRow);
            }
        }
コード例 #15
0
ファイル: PurchaseOrderRequest.cs プロジェクト: Osama91/CCWFM
        private TblPurchaseOrderDetailRequest UpdateOrInsertTblPurchaseOrderDetailRequest(TblPurchaseOrderDetailRequest newRow, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in context.TblPurchaseOrderDetailRequests
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    newRow.RemaningQty = newRow.Qty;
                    context.TblPurchaseOrderDetailRequests.AddObject(newRow);
                }
                context.SaveChanges();

                return(newRow);
            }
        }
コード例 #16
0
ファイル: TechPack.cs プロジェクト: Osama91/CCWFM
 public tblTechPackBOMComment UpdateOrInsertTechPackBOMComment(tblTechPackBOMComment _tblTechPackBOMComment)
 {
     using (var context = new WorkFlowManagerDBEntities())
     {
         if (_tblTechPackBOMComment.Iserial == 0)
         {
             context.tblTechPackBOMComments.AddObject(_tblTechPackBOMComment);
             context.SaveChanges();
             return(_tblTechPackBOMComment);
         }
         else
         {
             var oldRow = context.tblTechPackBOMComments.Where(x => x.tblStyle == _tblTechPackBOMComment.tblStyle).FirstOrDefault();
             if (oldRow != null)
             {
                 SharedOperation.GenericUpdate(oldRow, _tblTechPackBOMComment, context);
                 context.SaveChanges();
             }
             return(oldRow);
         }
     }
 }
コード例 #17
0
        private TblBankStatDetail UpdateOrInsertBankStatDetail(TblBankStatDetail newRow, int index, out int outindex, string company)
        {
            outindex = index;
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var oldRow = (from e in context.TblBankStatDetails
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                    SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    context.TblBankStatDetails.AddObject(newRow);
                }

                context.SaveChanges();
                return(newRow);
            }
        }
コード例 #18
0
ファイル: TechPack.cs プロジェクト: Osama91/CCWFM
        public void InsertOrUpdateTBLTechPackDetail(tblTechPackHeader _techPackHeader, List <tblTechPackDetail> newTechPackDetailRows)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                //CheackHeader
                var oldtechPackHeaderRow = (from e in context.tblTechPackHeaders
                                            where e.Iserial == _techPackHeader.Iserial
                                            select e).SingleOrDefault();

                if (oldtechPackHeaderRow != null)
                {
                    SharedOperation.GenericUpdate(oldtechPackHeaderRow, _techPackHeader, context);
                    context.SaveChanges();
                    SaveTechPackDetailRows(oldtechPackHeaderRow, newTechPackDetailRows);
                }
                else
                {
                    context.tblTechPackHeaders.AddObject(_techPackHeader);
                    context.SaveChanges();
                    SaveTechPackDetailRows(_techPackHeader, newTechPackDetailRows);
                }
            }
        }
コード例 #19
0
ファイル: MarkUp.cs プロジェクト: Osama91/CCWFM
 private TblMarkupGroupProd UpdateOrInsertTblMarkupGroupProds(TblMarkupGroupProd newRow, bool save, int index, out int outindex, string company)
 {
     outindex = index;
     using (var entity = new WorkFlowManagerDBEntities())
     {
         if (save)
         {
             entity.TblMarkupGroupProds.AddObject(newRow);
         }
         else
         {
             var oldRow = (from e in entity.TblMarkupGroupProds
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 SharedOperation.GenericUpdate(oldRow, newRow, entity);
             }
         }
         entity.SaveChanges();
         return(newRow);
     }
 }
コード例 #20
0
 private TblDyeingOrderInvoiceDetail UpdateOrInsertDyeingOrderInvoiceDetail(TblDyeingOrderInvoiceDetail newRow, bool save, int index, out int outindex)
 {
     outindex = index;
     using (var context = new WorkFlowManagerDBEntities())
     {
         if (save)
         {
             context.TblDyeingOrderInvoiceDetails.AddObject(newRow);
         }
         else
         {
             var oldRow = (from e in context.TblDyeingOrderInvoiceDetails
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 SharedOperation.GenericUpdate(oldRow, newRow, context);
             }
         }
         context.SaveChanges();
         return(newRow);
     }
 }
コード例 #21
0
ファイル: PurchaseOrderRequest.cs プロジェクト: Osama91/CCWFM
        private TblPurchaseReceiveDetail UpdateOrInsertTblPurchaseReceiveDetail(TblPurchaseReceiveDetail newRow, int index, out int outindex)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in context.TblPurchaseReceiveDetails
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    var purchaseorderdetailIserial = newRow.TblPurchaseOrderDetailRequest;
                    newRow.TblPurchaseOrderDetailRequest1 = null;
                    newRow.TblPurchaseOrderDetailRequest  = purchaseorderdetailIserial;
                    SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    context.TblPurchaseReceiveDetails.AddObject(newRow);
                }
                context.SaveChanges();

                return(newRow);
            }
        }
コード例 #22
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);
            }
        }
コード例 #23
0
ファイル: StyleNA.cs プロジェクト: Osama91/CCWFM
        private TblStyleTNAHeader UpdateOrInsertTblStyleTNAHeader(TblStyleTNAHeader newRow, bool save, int index, int user, out int outindex)
        {
            outindex = index;
            try
            {
                //Check  Delivery Date Limit with Contract DeliveryDate
                bool res = CheckContractDeliveryDate(newRow);
                if (!res)
                {
                    throw new Exception("Invalid Warehouse Delivery According to Delivery Date in Contract");
                }



                using (var context = new WorkFlowManagerDBEntities())
                {
                    if (save)
                    {
                        var style = context.TblStyles.FirstOrDefault(t => t.Iserial == newRow.TblStyle);
                        //if (style.RequestTna!=true)
                        //{
                        //    throw new Exception("Cannot add TNA to this style because it doesn't require TNA");
                        //}
                        style.RequestTna    = false;
                        newRow.CreatedBy    = user;
                        newRow.CreationDate = DateTime.Now;
                        foreach (var item in newRow.TblStyleTNADetails)
                        {
                            item.CreatedBy    = user;
                            item.CreationDate = DateTime.Now;

                            //
                            foreach (var attchment in item.TblStyleTNADetailAttachments.ToList())
                            {
                                //TblStyleTNADetailAttachment newAttachment = new TblStyleTNADetailAttachment();
                                //newAttachment.TblStyleTNADetail = item.Iserial;
                                //newAttachment.galaryLink = StyleTNADetailFiles + newAttachment.galaryLink;
                                //newAttachment.FileName = attchment.FileName;

                                SaveFileToPath(StyleTNADetailFiles, attchment.ImageThumb, attchment.FileName);
                                attchment.ImageThumb = null;
                            }
                        }
                        context.TblStyleTNAHeaders.AddObject(newRow);
                    }
                    else
                    {
                        bool changePrice = false;
                        if (context.TblStyleTNAColorDetails.Any(wde => wde.TblStyleTNAHeader == newRow.Iserial))
                        {
                            var CostList = context.TblStyleTNAColorDetails.Where(wde => wde.TblStyleTNAHeader == newRow.Iserial).Select(w => w.LocalCost).ToList();

                            var minCost = CostList.Min(w => w.Value);
                            var maxCost = CostList.Max(w => w.Value);

                            if (minCost == maxCost)
                            {
                                changePrice = true;
                            }
                        }
                        var oldRow = (from e in context.TblStyleTNAHeaders
                                      where e.Iserial == newRow.Iserial
                                      select e).SingleOrDefault();
                        if (oldRow != null)
                        {
                            newRow.LastUpdatedDate = DateTime.Now;
                            newRow.LastUpdatedBy   = user;
                            SharedOperation.GenericUpdate(oldRow, newRow, context);
                            foreach (var row in newRow.TblStyleTNADetails.ToList())
                            {
                                var oldColorRow = (from e in context.TblStyleTNADetails
                                                   where e.Iserial == row.Iserial && e.TblStyleTNAHeader == row.TblStyleTNAHeader
                                                   select e).SingleOrDefault();
                                if (oldColorRow != null)
                                {
                                    row.CreatedBy          = oldColorRow.CreatedBy;
                                    row.CreationDate       = oldColorRow.CreationDate;
                                    row.LastUpdatedDate    = DateTime.Now;
                                    row.LastUpdatedBy      = user;
                                    row.TblStyleTNAHeader  = newRow.Iserial;
                                    row.TblStyleTNAHeader1 = null;

                                    SharedOperation.GenericUpdate(oldColorRow, row, context);

                                    //Update Or Insert DetailAttachment
                                    if (row != null)
                                    {
                                        foreach (var attchment in row.TblStyleTNADetailAttachments.ToList())
                                        {
                                            TblStyleTNADetailAttachment newAttachment = new TblStyleTNADetailAttachment();
                                            newAttachment.TblStyleTNADetail = row.Iserial;
                                            newAttachment.galaryLink        = StyleTNADetailFiles + newAttachment.galaryLink;
                                            newAttachment.FileName          = attchment.FileName;

                                            SaveFileToPath(StyleTNADetailFiles, attchment.ImageThumb, attchment.FileName);

                                            context.TblStyleTNADetailAttachments.AddObject(newAttachment);
                                        }
                                        context.SaveChanges();
                                    }
                                }
                                else
                                {
                                    row.CreatedBy         = user;
                                    row.CreationDate      = DateTime.Now;
                                    row.TblStyleTNAHeader = newRow.Iserial;
                                    oldRow.TblStyleTNADetails.Add(row);
                                    // newRow.TblStyleTNADetails.Add(row);
                                    //context.TblStyleTNADetails.AddObject(row);
                                    context.SaveChanges();

                                    foreach (var attchment in row.TblStyleTNADetailAttachments.ToList())
                                    {
                                        TblStyleTNADetailAttachment newAttachment = new TblStyleTNADetailAttachment();
                                        newAttachment.TblStyleTNADetail = row.Iserial;
                                        newAttachment.galaryLink        = StyleTNADetailFiles + newAttachment.galaryLink;
                                        newAttachment.FileName          = attchment.FileName;
                                        SaveFileToPath(StyleTNADetailFiles, attchment.ImageThumb, attchment.FileName);
                                        context.TblStyleTNADetailAttachments.AddObject(newAttachment);
                                        context.SaveChanges();
                                    }
                                }
                            }

                            foreach (var row in newRow.TblStyleTNAColorDetails.ToList())
                            {
                                var oldColorRow = (from e in context.TblStyleTNAColorDetails
                                                   where e.Iserial == row.Iserial && e.TblStyleTNAHeader == row.TblStyleTNAHeader
                                                   select e).SingleOrDefault();
                                if (oldColorRow != null)
                                {
                                    row.TblStyleTNAHeader = newRow.Iserial;
                                    // row.TblStyleTNAHeader1 = null;
                                    if (changePrice)
                                    {
                                        row.LocalCost     = newRow.LocalCost;
                                        row.ExchangeRate  = newRow.ExchangeRate;
                                        row.FabricCost    = newRow.FabricCost;
                                        row.AccCost       = newRow.AccCost;
                                        row.OperationCost = newRow.OperationCost;
                                    }
                                    SharedOperation.GenericUpdate(oldColorRow, row, context);
                                }
                                else
                                {
                                    row.TblStyleTNAHeader  = newRow.Iserial;
                                    row.TblStyleTNAHeader1 = null;
                                    context.TblStyleTNAColorDetails.AddObject(row);
                                }
                            }
                        }
                    }

                    context.SaveChanges();

                    return(newRow = context.TblStyleTNAHeaders.Include("TblStyleTNADetails").Include("TblStyleTNAColorDetails.TblColor1")
                                    .FirstOrDefault(x => x.Iserial == newRow.Iserial));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #24
0
ファイル: ContractService.svc.cs プロジェクト: Osama91/CCWFM
        private TblContractHeader UpdateOrInsertContractHeader(TblContractHeader newRow, int index, int userIserial, out int outindex, string company)
        {
            throw new Exception("Save Contracts On Stitch");

            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                try
                {
                    newRow.TblRetailOrderProductionType1 = null;
                    newRow.TblSubContractor1             = null;
                    newRow.TblLkpSeason1       = null;
                    newRow.TblLkpBrandSection1 = null;
                    var brandCode = newRow.BrandCode;
                    var report    = context.TblBrandContractReports.FirstOrDefault(bcr => bcr.BrandCode == brandCode);
                    if (report != null)
                    {
                        newRow.ContractReport = report.ReportName;
                    }
                    var oldRow = context.TblContractHeaders.FirstOrDefault(th => th.Iserial == newRow.Iserial);
                    newRow.Amount = newRow.TblContractDetails.Sum(r => r.Total);



                    var budgetAmount = CalculateBudget(newRow, context);

                    var contractsAmount = context.TblContractDetails
                                          .Include(nameof(TblContractDetail.TblContractHeader1)).Where(r =>
                                                                                                       r.TblContractHeader1.BrandCode == newRow.BrandCode && r.TblLkpBrandSection == newRow.TblLkpBrandSection &&
                                                                                                       r.TblContractHeader1.TblLkpSeason == newRow.TblLkpSeason).ToList()
                                          .Select(r => new Tuple <int?, decimal>(r.TblLkpBrandSection,
                                                                                 r.TblContractHeader1.TblRetailOrderProductionType == 1 ?
                                                                                 (r.Qty * r.Cost) : r.TblContractHeader1.TblRetailOrderProductionType == 2 ?
                                                                                 (r.Qty * (r.Cost - r.AccCost)) : r.TblContractHeader1.TblRetailOrderProductionType == 3 ?
                                                                                 (r.Qty * (r.Cost - r.AccCost - r.FabricCost)) : (r.Qty * r.Cost)
                                                                                 )).GroupBy(r => r.Item1).Select(r => new Tuple <int?, decimal>(r.Key, r.Sum(d => d.Item2))).ToList();

                    var tblContractDetail = new List <TblContractDetail>();
                    newRow.TblContractDetails.ToArray().ForEach(d => tblContractDetail.Add(d));
                    if (oldRow != null)// الهيدر موجود قبل كده
                    {
                        CheckBudget(newRow, oldRow, budgetAmount, contractsAmount);

                        if (!oldRow.Approved && newRow.Approved)// كده لسه معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        foreach (var item in newRow.TblContractDetails.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp;
                            //headeriserial = item.TblContractHeader;
                            item.TblContractHeader1 = null;
                            item.TblContractHeader  = newRow.Iserial;
                            UpdateOrInsertContractDetail(item, userIserial, 1, out temp);
                            item.TblContractHeader1Reference = null;
                        }
                        foreach (var item in newRow.TblContractPaymentByPeriods.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp;
                            item.TblContractHeader1 = null;
                            item.TblContractHeader  = newRow.Iserial;
                            UpdateOrInsertContractPaymentDetail(item, userIserial, 1, out temp);
                            item.TblContractHeader1Reference = null;
                        }
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                        var result = SharedOperation.GenericUpdate(oldRow, newRow, context);
                        if (result.Count() > 0)
                        {
                            newRow.LastChangeUser = userIserial;
                            newRow.LastChangeDate = DateTime.Now;
                        }
                    }
                    else// الهيدر ده جديد
                    {
                        CheckBudget(newRow, null, budgetAmount, contractsAmount);

                        var seqTo  = 443;//context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailTo");
                        var seqRow = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == seqTo);
                        newRow.Code = SharedOperation.HandelSequence(seqRow);
                        if (newRow.Approved)// كده معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        newRow.TblContractDetails.ForEach(cd => {
                            cd.TblColor1 = null; cd.TblSalesOrderColor1 = null;
                            cd.CreatedBy = userIserial; cd.CreationDate = DateTime.Now;
                        });
                        newRow.TblContractPaymentByPeriods.ForEach(cd => {
                            cd.CreatedBy = userIserial; cd.CreationDate = DateTime.Now;
                        });

                        if (newRow.TblContractDetails.FirstOrDefault() != null)
                        {
                            newRow.TblLkpBrandSection = newRow.TblContractDetails.FirstOrDefault().TblLkpBrandSection;
                        }

                        //   newRow.TblLkpBrandSection = null;
                        newRow.CreatedBy      = userIserial;
                        newRow.CreationDate   = DateTime.Now;
                        newRow.LastChangeDate = DateTime.Now;
                        newRow.LastChangeUser = userIserial;

                        context.TblContractHeaders.AddObject(newRow);
                    }
                    context.SaveChanges();
                }
                catch (Exception ex) { throw ex; }
                TblContractHeader rowTemp = newRow.Clone();
                try
                {
                    if (newRow.Approved)
                    {
                        try
                        {
                            var emailTo      = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailTo");
                            var emailFrom    = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailFrom");
                            var emailBody    = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailBody");
                            var emailSubject = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailSubject");
                            if (emailTo != null && emailFrom != null && emailBody != null &&
                                emailSubject != null &&
                                //!emailTo.sSetupValue.Split(';').Any(e => !SharedOperation.IsValidEmail(e)) &&
                                SharedOperation.IsValidEmail(emailFrom.sSetupValue))
                            {
                                string storeMail = emailTo.sSetupValue;
                                SharedOperation.SendEmail(null, emailFrom.sSetupValue,
                                                          emailTo.sSetupValue.Split(';').ToList(), string.Format(emailSubject.sSetupValue,
                                                                                                                 newRow.Code), string.Format(emailBody.sSetupValue, newRow.Code));
                            }
                        }
                        catch (Exception ex) { }
                    }
                    foreach (var item in GetContractDetail(0, int.MaxValue, newRow.Iserial))
                    {
                        var tblContractDetail = item.Clone();
                        tblContractDetail.TblLkpBrandSection1 = item.TblLkpBrandSection1;
                        tblContractDetail.TblSalesOrderColor1 = item.TblSalesOrderColor1;
                        rowTemp.TblContractDetails.Add(tblContractDetail);
                    }
                    foreach (var item in GetContractPaymentDetail(0, int.MaxValue, newRow.Iserial))
                    {
                        var tblContractPaymentByPeriod = item.Clone();
                        rowTemp.TblContractPaymentByPeriods.Add(tblContractPaymentByPeriod);
                    }
                    using (var db = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
                    {
                        rowTemp.Supplier = db.TBLsuppliers.FirstOrDefault(s => s.Iserial == newRow.SupplierIserial);
                        rowTemp.Currency = db.TblCurrencyTests.FirstOrDefault(c => c.Iserial == rowTemp.TblCurrency);
                    }
                }
                catch { }
                return(rowTemp);
            }
        }
コード例 #25
0
ファイル: PurchaseOrderRequest.cs プロジェクト: Osama91/CCWFM
        private TblPurchaseReceiveHeader UpdateOrInsertTblPurchaseReceiveHeader(TblPurchaseReceiveHeader newRow, int index, out int outindex, string createdBy, int userIserial)
        {
            outindex = index;
            var totallist = new List <TblPurchaseReceiveDetail>();

            using (var context = new WorkFlowManagerDBEntities())
            {
                var newrowRet = new TblPurchaseReceiveHeader();
                var oldRow    = (from e in context.TblPurchaseReceiveHeaders.Include("TblPurchaseReceiveDetails")
                                 where e.Iserial == newRow.Iserial
                                 select e).SingleOrDefault();
                if (oldRow != null)
                {
                    newRow.CreatedBy       = oldRow.CreatedBy;
                    newRow.CreationDate    = oldRow.CreationDate;
                    newRow.LastUpdatedBy   = createdBy;
                    newRow.LastUpdatedDate = DateTime.Now;
                    SharedOperation.GenericUpdate(oldRow, newRow, context);
                    var OlDheader = context.TblPurchaseOrderHeaderRequests.FirstOrDefault(w => w.Iserial == oldRow.TblPurchaseOrderHeaderRequest);
                    if (OlDheader.AxPurchase == null)
                    {
                        foreach (var VARIABLE in oldRow.TblPurchaseReceiveDetails)
                        {
                            totallist.Add(VARIABLE);
                        }
                    }
                }
                else
                {
                    var warehouse = context.TblWarehouses.FirstOrDefault(w => w.Iserial == newRow.TblWarehouse);

                    foreach (var VARIABLE in newRow.TblPurchaseReceiveDetails)
                    {
                        totallist.Add(VARIABLE);
                    }
                    newRow.TblPurchaseReceiveDetails.Clear();

                    if (totallist.Any(w => w.Qty > 0))
                    {
                        foreach (var variable in totallist.Where(x => x.Qty > 0))
                        {
                            newRow.TblPurchaseReceiveDetails.Add(variable);
                        }

                        var seqRow = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == warehouse.Receive);
                        newRow.DocCode       = SharedOperation.HandelSequence(seqRow);
                        newRow.CreatedBy     = createdBy;
                        newRow.CreationDate  = DateTime.Now;
                        newRow.TblInventType = 1;

                        context.TblPurchaseReceiveHeaders.AddObject(newRow);
                    }
                    if (totallist.Any(w => w.Qty < 0))
                    {
                        newrowRet = new TblPurchaseReceiveHeader
                        {
                            DocDate      = newRow.DocDate,
                            RefNo        = newRow.RefNo,
                            Notes        = newRow.Notes,
                            TblWarehouse = newRow.TblWarehouse,
                            Vendor       = newRow.Vendor,
                            TblPurchaseOrderHeaderRequest = newRow.TblPurchaseOrderHeaderRequest,
                            Iserial = 0,
                        };
                        newrowRet.TblPurchaseReceiveDetails.Clear();
                        foreach (var variable in totallist.Where(x => x.Qty < 0))
                        {
                            newrowRet.TblPurchaseReceiveDetails.Add(variable);
                        }

                        var seqRow = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == warehouse.RetReceive);
                        newrowRet.DocCode       = SharedOperation.HandelSequence(seqRow);
                        newrowRet.CreatedBy     = createdBy;
                        newrowRet.CreationDate  = DateTime.Now;
                        newrowRet.TblInventType = 2;
                        context.TblPurchaseReceiveHeaders.AddObject(newrowRet);
                    }
                }
                context.SaveChanges();

                //if (true)
                //{

                //}

                //var ListOfRec = (from e in context.TblPurchaseReceiveDetails
                //                 where e.TblPurchaseReceiveHeader == newRow.Iserial
                //                 select e).ToList();
                //newRow.TblPurchaseReceiveDetails = new System.Data.Objects.DataClasses.EntityCollection<TblPurchaseReceiveDetail>();
                //foreach (var item in ListOfRec)
                //{

                //    newRow.TblPurchaseReceiveDetails.Add(item);
                //}

                //foreach (var VARIABLE in newRow.TblPurchaseReceiveDetails)
                //{
                //    totallist.Add(VARIABLE);
                //}
                if (totallist.Any(w => w.Qty > 0))
                {
                    PoPlanPurchase(newRow.Iserial, userIserial);

                    ReceivepackingSlip(newRow.Iserial, userIserial);
                }
                if (totallist.Any(w => w.Qty < 0))
                {
                    PoPlanPurchase(newrowRet.Iserial, userIserial);
                    //var header = context.TblPurchaseReceiveHeaders.Include("TblPurchaseOrderHeaderRequest1").Include("TblPurchaseReceiveDetails.TblPurchaseOrderDetailRequest1").FirstOrDefault(w => w.Iserial == newrowRet.Iserial);
                    ReceivepackingSlip(newrowRet.Iserial, userIserial);
                }
                if (totallist.Any(w => w.Qty > 0))
                {
                    var purchaserec = context.TblPurchaseReceiveHeaders.Include("TblPurchaseReceiveDetails").FirstOrDefault(w => w.Iserial == newRow.Iserial);

                    foreach (var item in purchaserec.TblPurchaseReceiveDetails.ToList())
                    {
                        var purchaseOrderDetailRequest = context.TblPurchaseOrderDetailRequests.FirstOrDefault(w => w.Iserial == item.TblPurchaseOrderDetailRequest);
                        purchaseOrderDetailRequest.BatchNo    = "";
                        purchaseOrderDetailRequest.ReceiveNow = 0;
                    }
                }
                if (totallist.Any(w => w.Qty < 0))
                {
                    var purchaserec = context.TblPurchaseReceiveHeaders.Include("TblPurchaseReceiveDetails").FirstOrDefault(w => w.Iserial == newrowRet.Iserial);
                    foreach (var item in purchaserec.TblPurchaseReceiveDetails.ToList())
                    {
                        var purchaseOrderDetailRequest = context.TblPurchaseOrderDetailRequests.FirstOrDefault(w => w.Iserial == item.TblPurchaseOrderDetailRequest);
                        purchaseOrderDetailRequest.BatchNo    = "";
                        purchaseOrderDetailRequest.ReceiveNow = 0;
                    }
                }
                return(newRow);
            }
        }
コード例 #26
0
        private TblAdjustmentHeader UpdateOrInsertAdjustmentHeader(TblAdjustmentHeader newRow, int index, int userIserial, out int outindex)// )
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                try
                {
                    var oldRow = context.TblAdjustmentHeaders.Include(nameof(TblAdjustmentHeader.TblAdjustmentDetails)).Include(nameof(
                                                                                                                                    TblAdjustmentHeader.TblWarehouse)).FirstOrDefault(th => th.Iserial == newRow.Iserial);
                    var tempwarhouse = newRow.TblWarehouse;
                    newRow.TblWarehouse = null;
                    foreach (var item in newRow.TblAdjustmentDetails)
                    {
                        item.AvailableQuantity  = item.ItemAdjustment.AvailableQuantity;
                        item.DifferenceQuantity = item.ItemAdjustment.DifferenceQuantity;
                        item.CountedQuantity    = item.ItemAdjustment.CountedQuantity;
                        item.Cost = item.ItemAdjustment.Cost;
                    }
                    if (oldRow != null)// الهيدر موجود قبل كده
                    {
                        //// هحذف الى اتحذف
                        //foreach (var item in oldRow.TblAdjustmentDetails)
                        //{
                        //    if (!newRow.TblAdjustmentDetails.Any(td => td.Iserial == item.Iserial))// مش موجود فى الجديد يبقى اتحذف
                        //        DeleteAdjustmentDetail(item);
                        //}
                        foreach (var item in newRow.TblAdjustmentDetails.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp, headeriserial;//item.ItemAdjustment
                            headeriserial                = item.AdjustmentHeaderIserial;
                            item.TblAdjustmentHeader     = null;
                            item.AdjustmentHeaderIserial = headeriserial;
                            UpdateOrInsertAdjustmentDetail(item, 1, out temp);
                            item.TblAdjustmentHeader = newRow;
                        }
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                        var result = SharedOperation.GenericUpdate(oldRow, newRow, context);

                        if (result.Count() > 0)
                        {
                            newRow.LastChangeUser = userIserial;
                            newRow.LastChangeDate = DateTime.Now;
                        }
                    }
                    else// الهيدر ده جديد
                    {
                        var warehouse = context.TblWarehouses.FirstOrDefault(w => w.Iserial == newRow.WarehouseIserial);
                        var seq       = warehouse.AdjustIn;
                        var seqRow    = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == seq);
                        newRow.Code = SharedOperation.HandelSequence(seqRow);

                        newRow.CreatedBy      = userIserial;
                        newRow.CreationDate   = DateTime.Now;
                        newRow.LastChangeDate = DateTime.Now;
                        newRow.LastChangeUser = userIserial;

                        context.TblAdjustmentHeaders.AddObject(newRow);
                    }
                    context.SaveChanges();
                    //if (newRow.EntityState != System.Data.EntityState.Detached && newRow.EntityState != System.Data.EntityState.Added)
                    //    context.Detach(newRow);
                    //if (newRow.TblWarehouse == null)
                    //    newRow.TblWarehouse = context.TblWarehouses.AsNoTracking().FirstOrDefault(w => w.Iserial == newRow.WarehouseIserial);// tempwarhouse;
                    foreach (var item in newRow.TblAdjustmentDetails)
                    {
                        GetAdjustmentItemDetails(context, item);
                    }
                }
                catch (Exception ex) { throw ex; }
                return(newRow);
            }
        }
コード例 #27
0
        public List <TblTradeAgreementDetail> SaveTradeAgreement(TblTradeAgreementTransaction header,
                                                                 out TblTradeAgreementTransaction savedHeader)
        {
            header.TblLkpSeason1 = null;
            savedHeader          = header;
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var oldTransaction = entities.TblTradeAgreementTransactions.FirstOrDefault(s =>
                                                                                           s.Iserial == header.Iserial);
                if (oldTransaction != null)
                {
                    SharedOperation.GenericUpdate(oldTransaction, header, entities);

                    foreach (var headerItem in header.TblTradeAgreementHeaders)
                    {
                        headerItem.TblTradeAgreementTransaction = oldTransaction.Iserial;
                        var oldRow = entities.TblTradeAgreementHeaders.FirstOrDefault(
                            x => x.Vendor == headerItem.Vendor && x.FromDate == headerItem.FromDate && x.ToDate == headerItem.ToDate);
                        if (oldRow != null)
                        {
                            headerItem.Iserial = oldRow.Iserial;
                            SharedOperation.GenericUpdate(oldRow, headerItem, entities);
                            foreach (var detailItem in headerItem.TblTradeAgreementDetails)
                            {
                                detailItem.TblTradeAgreementHeader = headerItem.Iserial;
                                if (detailItem.Iserial != 0)
                                {
                                    var olddetailRow = entities.TblTradeAgreementDetails.SingleOrDefault(
                                        s => s.Iserial == detailItem.Iserial);
                                    SharedOperation.GenericUpdate(olddetailRow, detailItem, entities);
                                }
                                else
                                {
                                    var tempDetail = new TblTradeAgreementDetail();
                                    tempDetail = detailItem.Clone();
                                    tempDetail.TblTradeAgreementHeader1 = null;
                                    entities.TblTradeAgreementDetails.AddObject(tempDetail);
                                }
                            }
                        }
                        else
                        {
                            var tempHeader = new TblTradeAgreementHeader();
                            tempHeader = headerItem.Clone();
                            tempHeader.TblTradeAgreementTransaction1 = null;
                            entities.TblTradeAgreementHeaders.AddObject(tempHeader);
                        }
                    }
                }
                else
                {
                    header.Serial = entities.TblTradeAgreementTransactions.Where(t =>
                                                                                 t.TblLkpSeason == header.TblLkpSeason
                                                                                 ).Select(t => t.Serial).DefaultIfEmpty(0).Max() + 1;
                    entities.TblTradeAgreementTransactions.AddObject(header);
                }

                entities.SaveChanges();

                List <TblTradeAgreementDetail> result = new List <TblTradeAgreementDetail>();
                header.TblTradeAgreementHeaders.ForEach(h => h.TblTradeAgreementDetails.ForEach(d => result.Add(d)));
                return(result);
            }
        }
コード例 #28
0
        private TblTradeAgreementDetail UpdateOrInsertTblTradeAgreementDetail(TblTradeAgreementDetail newRow,
                                                                              int index, out int outindex, int User)
        {
            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                var header = newRow.TblTradeAgreementHeader1;
                header.TblTradeAgreementTransaction1 = null;
                newRow.TblColor1                        = null;
                newRow.TblColor1Reference               = null;
                newRow.TblLkpSeason1                    = null;
                newRow.TblLkpSeason1Reference           = null;
                newRow.TblVendorPurchaseGroup1          = null;
                newRow.TblVendorPurchaseGroup1Reference = null;
                if (context.TblTradeAgreementHeaders.Any(
                        x => x.Vendor == header.Vendor && x.FromDate == header.FromDate && x.ToDate == header.ToDate))
                {
                    newRow.TblTradeAgreementHeader1 = null;
                    newRow.TblTradeAgreementHeader  = context.TblTradeAgreementHeaders.FirstOrDefault(
                        x => x.Vendor == header.Vendor && x.FromDate == header.FromDate && x.ToDate == header.ToDate).Iserial;
                    var oldRow = context.TblTradeAgreementDetails.
                                 SingleOrDefault(e => e.Iserial == newRow.Iserial);
                    if (oldRow != null)
                    {
                        newRow.CreatedBy    = oldRow.CreatedBy;
                        newRow.CreationDate = oldRow.CreationDate;

                        newRow.LastUpdatedBy   = User;
                        newRow.LastUpdatedDate = DateTime.Now;
                        SharedOperation.GenericUpdate(oldRow, newRow, context);
                    }
                    else
                    {
                        newRow.CreatedBy       = User;
                        newRow.LastUpdatedBy   = User;
                        newRow.CreationDate    = DateTime.Now;
                        newRow.LastUpdatedDate = DateTime.Now;
                        context.TblTradeAgreementDetails.AddObject(newRow);
                    }
                }
                else
                {
                    context.TblTradeAgreementHeaders.AddObject(newRow.TblTradeAgreementHeader1);
                    //newRow.TblTradeAgreementHeader1 = null;
                    var oldRow = context.TblTradeAgreementDetails.SingleOrDefault(e => e.Iserial == newRow.Iserial);
                    if (oldRow != null)
                    {
                        context.TblTradeAgreementDetails.DeleteObject(oldRow);
                    }
                    else
                    {
                        newRow.LastUpdatedBy   = User;
                        newRow.LastUpdatedDate = DateTime.Now;
                        newRow.CreatedBy       = User;
                        newRow.CreationDate    = DateTime.Now;
                        context.TblTradeAgreementDetails.AddObject(newRow);
                    }
                    newRow.Iserial = 0;
                }
                context.SaveChanges();
                return(newRow);
            }
        }
コード例 #29
0
        private TblBankStatHeader UpdateOrInsertBankStatHeader(TblBankStatHeader newRow, int index, int userIserial,
                                                               out int outindex, string company)
        {
            outindex = index;
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                try
                {
                    newRow.TblBank1     = null;
                    newRow.TblCurrency1 = null;
                    var oldRow = context.TblBankStatHeaders.Include(nameof(TblBankStatHeader.TblBankStatDetails)).FirstOrDefault(th => th.Iserial == newRow.Iserial);
                    if (oldRow != null)// الهيدر موجود قبل كده
                    {
                        newRow.LastChangeUser = userIserial;
                        newRow.LastChangeDate = DateTime.Now;
                        if (!oldRow.MatchApproved && newRow.MatchApproved)// كده لسه معموله ابروف
                        {
                            newRow.MatchApproveDate = DateTime.Now;
                            newRow.MatchApprovedBy  = userIserial;
                        }
                        if (!oldRow.Approved && newRow.Approved)// كده لسه معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        foreach (var item in newRow.TblBankStatDetails.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp, headeriserial;
                            headeriserial           = item.TblBankStatHeader;
                            item.TblBankStatHeader1 = null;
                            item.TblBankStatHeader  = headeriserial;
                            UpdateOrInsertBankStatDetail(item, 1, out temp, company);
                            item.TblBankStatHeader1 = newRow;
                        }
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                        SharedOperation.GenericUpdate(oldRow, newRow, context);
                    }
                    else// الهيدر ده جديد
                    {
                        if (newRow.MatchApproved)// كده معموله ابروف
                        {
                            newRow.MatchApproveDate = DateTime.Now;
                            newRow.MatchApprovedBy  = userIserial;
                        }
                        if (newRow.Approved)// كده معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        newRow.CreatedBy      = userIserial;
                        newRow.CreationDate   = DateTime.Now;
                        newRow.LastChangeDate = DateTime.Now;
                        newRow.LastChangeUser = userIserial;

                        context.TblBankStatHeaders.AddObject(newRow);
                    }
                    context.SaveChanges();
                }
                catch (Exception ex) { throw ex; }
                return(newRow);
            }
        }
コード例 #30
0
ファイル: TechPack.cs プロジェクト: Osama91/CCWFM
        private void SaveTechPackDetailRows(tblTechPackHeader HeaderRow, List <tblTechPackDetail> DetailsRow)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                try
                {
                    foreach (var newRow in DetailsRow)
                    {
                        newRow.tblTechPackHeader = HeaderRow.Iserial;
                        newRow.LastChangeDate    = DateTime.Now;
                        var oldRow = (from e in context.tblTechPackDetails
                                      where e.Iserial == newRow.Iserial
                                      select e).SingleOrDefault();

                        if (!string.IsNullOrEmpty(newRow.galaryLink))
                        {
                            SaveImageToPath(newRow.galaryLink, newRow.ImageThumb);
                            //newRow.galaryLink = "D:\\TechPackImages\\" + newRow.galaryLink;
                            newRow.galaryLink = TechPackImagesWrite + newRow.galaryLink;
                        }
                        else
                        {
                            newRow.galaryLink = oldRow.galaryLink;
                        }

                        //Update
                        if (oldRow != null)
                        {
                            if (string.IsNullOrEmpty(newRow.galaryLink))
                            {
                                newRow.galaryLink = oldRow.galaryLink;
                                newRow.ImageName  = oldRow.ImageName;
                            }
                            oldRow.ImageThumb     = null;
                            newRow.ImageThumb     = null;
                            oldRow.LastChangeDate = DateTime.Now;
                            if (oldRow.Description == newRow.Description &&
                                oldRow.galaryLink == newRow.galaryLink &&
                                oldRow.ImageName == newRow.ImageName &&
                                oldRow.tblTechPackPart == newRow.tblTechPackPart)
                            {
                                //Don't Log
                            }
                            else
                            {
                                SaveTBLTechPackLog(newRow);
                            }
                            SharedOperation.GenericUpdate(oldRow, newRow, context);
                            context.SaveChanges();
                        }
                        else
                        {
                            context.tblTechPackDetails.AddObject(newRow);
                            newRow.ImageThumb = null;
                            context.SaveChanges();
                            SaveTBLTechPackLog(newRow);
                        }
                    }
                }
                catch { }
            }
        }