Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                CustomList <HouseKeepingValue> lstHKEntry = HouseKeepingList;
                if (lstHKEntry.Count == 0)
                {
                    HouseKeepingValue newHouseKeepingEntry = new HouseKeepingValue();
                    lstHKEntry.Add(newHouseKeepingEntry);
                }
                CustomList <HouseKeepingValue>     lstParent = ParentList;
                CustomList <HousekeepingHierarchy> lstChild  = ChildList;
                CustomList <HousekeepingHierarchy> savedList = new CustomList <HousekeepingHierarchy>();
                foreach (HouseKeepingValue hKV in lstParent)
                {
                    if (hKV.IsSaved)
                    {
                        HousekeepingHierarchy childObj = ChildList.Find(f => f.ParentID == hKV.HKID);
                        if (childObj.IsNotNull())
                        {
                            savedList.Add(childObj);
                        }
                        else
                        {
                            HousekeepingHierarchy obj = new HousekeepingHierarchy();
                            obj.ParentID = hKV.HKID;
                            savedList.Add(obj);
                        }
                    }
                    else
                    {
                        HousekeepingHierarchy childObj = ChildList.Find(f => f.ParentID == hKV.HKID);
                        if (childObj.IsNotNull())
                        {
                            childObj.Delete();
                            savedList.Add(childObj);
                        }
                    }
                }

                SetDataFromControls(ref lstHKEntry);

                if (!CheckUserAuthentication(lstHKEntry))
                {
                    return;
                }
                manager.SaveHKEntry(ref lstHKEntry, ref savedList);
                this.SuccessMessage = (StaticInfo.SavedSuccessfullyMsg);
            }
            catch (SqlException ex)
            {
                this.ErrorMessage = (ExceptionHelper.getSqlExceptionMessage(ex));
            }
            catch (Exception ex)
            {
                this.ErrorMessage = (ExceptionHelper.getExceptionMessage(ex));
            }
        }
Пример #2
0
        public void DeleteHKEntry(ref CustomList <HouseKeepingValue> HKList, ref CustomList <HouseKeepingValue> lstParent, ref CustomList <HousekeepingHierarchy> lstChild)
        {
            ConnectionManager conManager     = new ConnectionManager(ConnectionName.HR);
            Boolean           blnTranStarted = false;

            try
            {
                conManager.BeginTransaction();

                ReSetSPName(HKList);

                blnTranStarted = true;

                foreach (HouseKeepingValue h in HKList)
                {
                    h.Delete();
                }
                CustomList <HousekeepingHierarchy> hKHList        = new CustomList <HousekeepingHierarchy>();
                CustomList <HousekeepingHierarchy> deletedHKHList = new CustomList <HousekeepingHierarchy>();
                foreach (HouseKeepingValue hKV in lstParent)
                {
                    HousekeepingHierarchy deletedObj = lstChild.Find(f => f.ParentID == hKV.HKID);
                    if (deletedObj.IsNotNull())
                    {
                        deletedHKHList.Add(deletedObj);
                    }
                }
                conManager.SaveDataCollectionThroughCollection(blnTranStarted, deletedHKHList, HKList);

                deletedHKHList.AcceptChanges();
                hKHList.AcceptChanges();
                HKList.AcceptChanges();

                conManager.CommitTransaction();
                blnTranStarted = false;
                conManager.Dispose();
            }
            catch (Exception Ex)
            {
                conManager.RollBack();
                throw Ex;
            }
            finally
            {
                if (conManager.IsNotNull())
                {
                    conManager.Dispose();
                }
            }
        }
Пример #3
0
        public void SaveHKEntry(ref CustomList <HouseKeepingValue> HKList, ref CustomList <HouseKeepingValue> lstParent, ref CustomList <HousekeepingHierarchy> lstChild)
        {
            ConnectionManager conManager     = new ConnectionManager(ConnectionName.HR);
            Boolean           blnTranStarted = false;

            try
            {
                conManager.BeginTransaction();

                ReSetSPName(HKList);

                blnTranStarted = true;

                Object scope_Identity = null;
                if (HKList[0].IsAdded)
                {
                    scope_Identity = conManager.InsertData(blnTranStarted, HKList);
                }
                else
                {
                    conManager.SaveDataCollectionThroughCollection(blnTranStarted, HKList);
                }

                CustomList <HousekeepingHierarchy> hKHList        = new CustomList <HousekeepingHierarchy>();
                CustomList <HousekeepingHierarchy> deletedHKHList = new CustomList <HousekeepingHierarchy>();
                foreach (HouseKeepingValue hKV in lstParent)
                {
                    if (!hKV.IsSaved)
                    {
                        HousekeepingHierarchy deletedObj = lstChild.Find(f => f.ParentID == hKV.HKID);
                        if (deletedObj.IsNotNull())
                        {
                            deletedHKHList.Add(deletedObj);
                        }
                    }
                    if (hKV.IsSaved)
                    {
                        HousekeepingHierarchy hKH        = new HousekeepingHierarchy();
                        HousekeepingHierarchy deletedHKH = new HousekeepingHierarchy();

                        if (scope_Identity.IsNull())
                        {
                            hKH.HKID        = HKList[0].HKID;
                            deletedHKH.HKID = HKList[0].HKID;
                        }
                        else
                        {
                            hKH.HKID        = Convert.ToInt32(scope_Identity);
                            deletedHKH.HKID = Convert.ToInt32(scope_Identity);
                            HKList[0].HKID  = Convert.ToInt32(scope_Identity);
                        }

                        hKH.ParentID        = hKV.HKID;
                        deletedHKH.ParentID = hKV.HKID;
                        hKHList.Add(hKH);
                        deletedHKHList.Add(deletedHKH);
                    }
                }
                deletedHKHList.ForEach(f => f.Delete());
                hKHList.InsertSpName = "spInsertHousekeepingHierarchy";
                hKHList.UpdateSpName = "spUpdateHousekeepingHierarchy";
                hKHList.DeleteSpName = "spDeleteHousekeepingHierarchy";

                deletedHKHList.DeleteSpName = "spDeleteHousekeepingHierarchy";

                conManager.SaveDataCollectionThroughCollection(blnTranStarted, deletedHKHList, hKHList);

                deletedHKHList.AcceptChanges();
                hKHList.AcceptChanges();

                conManager.CommitTransaction();
                blnTranStarted = false;
                conManager.Dispose();
            }
            catch (Exception Ex)
            {
                conManager.RollBack();
                throw Ex;
            }
            finally
            {
                if (conManager.IsNotNull())
                {
                    conManager.Dispose();
                }
            }
        }