示例#1
0
        public List <AppDuesAndDeduct_Setting> SelectAllAppDuesAndDeduct(string Company_Id, string Branch_Id, string AppSettingType)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            try
            {
                OpenEntityConnection();


                List <AppDuesAndDeduct_Setting> objectList = new List <AppDuesAndDeduct_Setting>();

                var objlist = (from objLinq in objPharmaEntities.AppDuesAndDeduct_Setting
                               where objLinq.Company_Id == Company_Id && objLinq.Branch_Id == Branch_Id && objLinq.AppSettingType == AppSettingType
                               //&& objLinq.Grade_Id == Grade_Id



                               select new
                {
                    Branch_Id = objLinq.Branch_Id,
                    Company_Id = objLinq.Company_Id,
                    AppSettingType = objLinq.AppSettingType,
                    CalcOnType = objLinq.CalcOnType,
                    HireItemId = objLinq.HireItemId
                }).ToList();



                foreach (var obj in objlist)
                {
                    AppDuesAndDeduct_Setting objGradeHiringItemDL = new AppDuesAndDeduct_Setting();

                    objGradeHiringItemDL.Branch_Id      = obj.Branch_Id;
                    objGradeHiringItemDL.Company_Id     = obj.Company_Id;
                    objGradeHiringItemDL.AppSettingType = obj.AppSettingType;
                    objGradeHiringItemDL.CalcOnType     = obj.CalcOnType;
                    objGradeHiringItemDL.HireItemId     = obj.HireItemId;

                    objectList.Add(objGradeHiringItemDL);
                }


                return(objectList);

                //Rec_No ,ReferenceNo ,BranchAccount_Id
                //,Company_Id ,Branch_Id ,Emp_Serial_No ,TransDate ,FromDate ,ToDate ,BackDate ,Reason ,InsUser ,InsDate ,Order_Status ,PlaceOfResidence ,DocumentPath ,BranchAccountTypeName ,StatusName
            }
            catch (Exception ex)
            {
                catchEntityvalidation((System.Data.Entity.Validation.DbEntityValidationException)ex, System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(),
                                      this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                ex.InnerException.Message.ToString();
                return(null);
            }
            finally
            {
                CloseEntityConnection();
            }
        }
示例#2
0
        //public bool SaveDateAppDuesAndDeduct(List<AppDuesAndDeduct_Setting> ListDtls)
        //{
        //    StackFrame stackFrame = new StackFrame();
        //    MethodBase methodBase = stackFrame.GetMethod();

        //    var strErrorMessage = string.Empty;
        //    //  ObjWorkFlow_HdrDL.InsUser = "******";

        //    // ObjCommTransHeaderDL.InsDate = DateTime.Now.ToString("dd/MM/yyyy");
        //    bool result = true;

        //    //using (System.Data.Entity.DbContextTransaction dbTran = objPharmaEntities.Database.BeginTransaction())
        //    //{
        //    try
        //    {
        //        if (objPharmaEntities.Database.Connection.State == System.Data.ConnectionState.Closed)
        //        {
        //            objPharmaEntities.Database.Connection.Open();
        //        }

        //        string strBranch_Id = ListDtls[0].Branch_Id.ToString();
        //        string strCompany_Id = ListDtls[0].Company_Id.ToString();
        //        string strAppSettingType = ListDtls[0].AppSettingType.ToString();

        //        //if (!String.IsNullOrEmpty(strBranch_Id) && !String.IsNullOrEmpty(strCompany_Id) && !String.IsNullOrEmpty(strCompany_Id))
        //        //{
        //        //    result = DeleteAppDuesAndDeduct(strBranch_Id, strCompany_Id, strAppSettingType);
        //        //}


        //            foreach (AppDuesAndDeduct_Setting Obj_Dtls in ListDtls)
        //            {
        //                if (Obj_Dtls != null)
        //                {

        //                    AppDuesAndDeduct_Setting objlist = (from objLinq in objPharmaEntities.AppDuesAndDeduct_Setting
        //                                                        where objLinq.Company_Id == Obj_Dtls.Company_Id && objLinq.Branch_Id == Obj_Dtls.Branch_Id && objLinq.AppSettingType == Obj_Dtls.AppSettingType
        //                                                        && objLinq.HireItemId == Obj_Dtls.HireItemId
        //                                                        select objLinq).FirstOrDefault();

        //                       if (objlist !=null)
        //                       {
        //                            //bool resultupdate = objPharmaEntities.ChangeTracker.HasChanges();
        //                            //if (resultupdate)
        //                            //{
        //                                objlist.CalcOnType = Obj_Dtls.CalcOnType;
        //                                objlist.CheckedStatus = Obj_Dtls.CheckedStatus;
        //                                result = objPharmaEntities.SaveChanges() > 0;
        //                            //}
        //                            //else
        //                            //{
        //                            //    return true;
        //                            //}
        //                       }
        //                       else
        //                       {


        //                                AppDuesAndDeduct_Setting loclDtls = new AppDuesAndDeduct_Setting
        //                                {
        //                                    Branch_Id = Obj_Dtls.Branch_Id,
        //                                    Company_Id = Obj_Dtls.Company_Id,
        //                                    AppSettingType = Obj_Dtls.AppSettingType,
        //                                    CalcOnType = Obj_Dtls.CalcOnType,
        //                                    HireItemId = Obj_Dtls.HireItemId,
        //                                    CheckedStatus = Obj_Dtls.CheckedStatus
        //                                };

        //                                objPharmaEntities.AppDuesAndDeduct_Setting.Add(loclDtls);
        //                                //saves all above operations within one transaction
        //                         result= objPharmaEntities.SaveChanges()> 0 ;
        //                   }
        //                    // dbTran.Commit();
        //                    // }



        //                }
        //            }


        //        //commit transaction
        //        //  dbTran.Commit();
        //    }
        //    catch (DbEntityValidationException ex)
        //    {


        //        // Retrieve the error messages as a list of strings.
        //        var errorMessages = ex.EntityValidationErrors
        //                .SelectMany(x => x.ValidationErrors)
        //                .Select(x => x.ErrorMessage);

        //        // Join the list to a single string.
        //        var fullErrorMessage = string.Join("; ", errorMessages);

        //        // Combine the original exception message with the new one.
        //        var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
        //        strErrorMessage = fullErrorMessage;
        //        // Throw a new DbEntityValidationException with the improved exception message.
        //        throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
        //        //((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage
        //        //   dbTran.Rollback();
        //        result = false;

        //    }

        //    catch (Exception ex)
        //    {

        //        //Rollback transaction if exception occurs
        //        //  dbTran.Rollback();
        //        result = false;

        //    }

        //    finally
        //    {
        //        objPharmaEntities.Database.Connection.Close();
        //        //  dbTran.Dispose();

        //        if (!string.IsNullOrEmpty(strErrorMessage))
        //        {
        //            SaveErrorLog(System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(), strErrorMessage, this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
        //        }

        //    }
        //    return result;

        //    //  }

        //}
        public bool SaveDateAppDuesAndDeduct(List <AppDuesAndDeduct_Setting> ListDtls)
        {
            StackFrame stackFrame = new StackFrame();
            MethodBase methodBase = stackFrame.GetMethod();

            var strErrorMessage = string.Empty;
            //  ObjWorkFlow_HdrDL.InsUser = "******";

            // ObjCommTransHeaderDL.InsDate = DateTime.Now.ToString("dd/MM/yyyy");
            bool result = true;

            //using (System.Data.Entity.DbContextTransaction dbTran = objPharmaEntities.Database.BeginTransaction())
            //{
            try
            {
                if (objPharmaEntities.Database.Connection.State == System.Data.ConnectionState.Closed)
                {
                    objPharmaEntities.Database.Connection.Open();
                }

                string strBranch_Id      = ListDtls[0].Branch_Id.ToString();
                string strCompany_Id     = ListDtls[0].Company_Id.ToString();
                string strAppSettingType = ListDtls[0].AppSettingType.ToString();

                //if (!String.IsNullOrEmpty(strBranch_Id) && !String.IsNullOrEmpty(strCompany_Id) && !String.IsNullOrEmpty(strCompany_Id))
                //{
                //    result = DeleteAppDuesAndDeduct(strBranch_Id, strCompany_Id, strAppSettingType);
                //}


                foreach (AppDuesAndDeduct_Setting Obj_Dtls in ListDtls)
                {
                    if (Obj_Dtls != null)
                    {
                        AppDuesAndDeduct_Setting objlist = (from objLinq in objPharmaEntities.AppDuesAndDeduct_Setting
                                                            where objLinq.Company_Id == Obj_Dtls.Company_Id && objLinq.Branch_Id == Obj_Dtls.Branch_Id && objLinq.AppSettingType == Obj_Dtls.AppSettingType &&
                                                            objLinq.HireItemId == Obj_Dtls.HireItemId
                                                            select objLinq).FirstOrDefault();

                        if (objlist != null)
                        {
                            //bool resultupdate = objPharmaEntities.ChangeTracker.HasChanges();
                            //if (resultupdate)
                            //{
                            objlist.CalcOnType    = Obj_Dtls.CalcOnType;
                            objlist.CheckedStatus = Obj_Dtls.CheckedStatus;
                            result = objPharmaEntities.SaveChanges() > 0;
                            result = true;
                            //}
                            //else
                            //{
                            //    return true;
                            //}
                        }
                        else
                        {
                            AppDuesAndDeduct_Setting loclDtls = new AppDuesAndDeduct_Setting
                            {
                                Branch_Id      = Obj_Dtls.Branch_Id,
                                Company_Id     = Obj_Dtls.Company_Id,
                                AppSettingType = Obj_Dtls.AppSettingType,
                                CalcOnType     = Obj_Dtls.CalcOnType,
                                HireItemId     = Obj_Dtls.HireItemId,
                                CheckedStatus  = Obj_Dtls.CheckedStatus
                            };

                            objPharmaEntities.AppDuesAndDeduct_Setting.Add(loclDtls);
                            //saves all above operations within one transaction
                            result = objPharmaEntities.SaveChanges() > 0;
                        }
                        // dbTran.Commit();
                        // }
                    }
                }


                //commit transaction
                //  dbTran.Commit();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
                strErrorMessage = fullErrorMessage;
                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                //((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage
                //   dbTran.Rollback();
                result = false;
            }

            catch (Exception ex)
            {
                //Rollback transaction if exception occurs
                //  dbTran.Rollback();
                result = false;
            }

            finally
            {
                objPharmaEntities.Database.Connection.Close();
                //  dbTran.Dispose();

                if (!string.IsNullOrEmpty(strErrorMessage))
                {
                    SaveErrorLog(System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(), strErrorMessage, this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString());
                }
            }
            return(result);

            //  }
        }