Exemplo n.º 1
0
        private int DeleteTblGlobalRetailBusinessBudgetMainDetail(TblGlobalRetailBusinessBudgetMainDetail row)
        {
            using (var db = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in db.TblGlobalRetailBusinessBudgetMainDetails
                              where e.Iserial == row.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    db.DeleteObject(oldRow);
                }

                db.SaveChanges();
            }
            return(row.Iserial);
        }
Exemplo n.º 2
0
        public void SaveDetailRow()
        {
            foreach (var row in TransactionHeader.DetailsList.Where(x => x.Iserial != -1))
            {
                var  valiationCollection = new List <ValidationResult>();
                bool isvalid             = Validator.TryValidateObject(row,
                                                                       new ValidationContext(row, null, null), valiationCollection, true);
                var  valiationCollectionHeader = new List <ValidationResult>();
                bool isvalidHeader             = Validator.TryValidateObject(TransactionHeader,
                                                                             new ValidationContext(TransactionHeader, null, null), valiationCollectionHeader, true);
                TransactionHeader.TransactionType = TransactionType;
                if (
                    TransactionHeader.DetailsList.Count(
                        x =>
                        x.Brand == row.Brand &&
                        x.TblLkpBrandSection == row.TblLkpBrandSection &&
                        x.TblLkpSeason == row.TblLkpSeason &&
                        row.TblBudgetItem == x.TblBudgetItem) > 1)
                {
                    MessageBox.Show("Cannot Duplicate The Full Criteria");
                    row.BrandSectionPerRow = null;
                    row.SeasonPerRow       = null;
                    row.BudgetItemPerRow   = null;

                    isvalid = false;
                }

                if (isvalid && isvalidHeader)
                {
                    var data = new TblGlobalRetailBusinessBudgetMainDetail();
                    data.InjectFrom(row);
                    row.TblGlobalRetailBusinessBudget = TransactionHeader.Iserial;
                    if (row.TblGlobalRetailBusinessBudget == 0)
                    {
                        data.TblGlobalRetailBusinessBudget1 =
                            (TblGlobalRetailBusinessBudget)
                            new TblGlobalRetailBusinessBudget().InjectFrom(TransactionHeader);
                    }
                    data.TblGlobalRetailBusinessBudgetDetails = new ObservableCollection <TblGlobalRetailBusinessBudgetDetail>();

                    GenericMapper.InjectFromObCollection(data.TblGlobalRetailBusinessBudgetDetails,
                                                         row.DetailsList);

                    bool save = row.Iserial == 0;
                    if (save)
                    {
                        if (AllowAdd)
                        {
                            Loading = true;
                            Client.UpdateOrInsertTblGlobalRetailBusinessBudgetMainDetailAsync(data, true,
                                                                                              TransactionHeader.DetailsList.IndexOf(row), LoggedUserInfo.Iserial);
                        }

                        else
                        {
                            MessageBox.Show("You are Not Allowed to Add");
                        }
                    }
                    else
                    {
                        if (AllowUpdate)
                        {
                            Loading = true;
                            Client.UpdateOrInsertTblGlobalRetailBusinessBudgetMainDetailAsync(data, false,
                                                                                              TransactionHeader.DetailsList.IndexOf(row), LoggedUserInfo.Iserial);
                        }
                        else
                        {
                            MessageBox.Show("You are Not Allowed to Update");
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public TblGlobalRetailBusinessBudgetMainDetail UpdateOrInsertTblGlobalRetailBusinessBudgetMainDetail(TblGlobalRetailBusinessBudgetMainDetail newRow, bool save, int index, out int outindex, int userIserial)
 {
     using (var db = new WorkFlowManagerDBEntities())
     {
         outindex = index;
         if (save)
         {
             if (newRow.TblGlobalRetailBusinessBudget1 != null)
             {
                 var headerRow = newRow.TblGlobalRetailBusinessBudget1;
                 var oldRow    = (from e in db.TblGlobalRetailBusinessBudgets
                                  where e.Year == headerRow.Year && e.TransDate == headerRow.TransDate && headerRow.TransactionType == e.TransactionType
                                  select e).SingleOrDefault();
                 if (oldRow != null)
                 {
                     newRow.TblGlobalRetailBusinessBudget  = oldRow.Iserial;
                     newRow.TblGlobalRetailBusinessBudget1 = null;
                 }
             }
             db.TblGlobalRetailBusinessBudgetMainDetails.AddObject(newRow);
             db.SaveChanges();
         }
         else
         {
             var oldRow = (from e in db.TblGlobalRetailBusinessBudgetMainDetails
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 GenericUpdate(oldRow, newRow, db);
                 foreach (var detailRow in newRow.TblGlobalRetailBusinessBudgetDetails)
                 {
                     var detailOldRow = (from e in db.TblGlobalRetailBusinessBudgetDetails
                                         where e.Iserial == detailRow.Iserial
                                         select e).SingleOrDefault();
                     if (detailOldRow != null)
                     {
                         GenericUpdate(detailOldRow, detailRow, db);
                     }
                     else
                     {
                         detailRow.TblGlobalRetailBusinessBudgetMainDetail1 = null;
                         detailRow.TblGlobalRetailBusinessBudgetMainDetail  = newRow.Iserial;
                         db.TblGlobalRetailBusinessBudgetDetails.AddObject(detailRow);
                     }
                 }
             }
         }
         db.SaveChanges();
         return(newRow);
     }
 }