public List <WORK_ORDER_MAIN> GetWorkOrderDetailByPartNumberOrderNumber(WORK_ORDER_MAIN paramEntity = null)
        {
            List <WORK_ORDER_MAIN> lstEntity = null;

            try
            {
                if (!DB.IsNotNullOrEmpty())
                {
                    return(lstEntity);
                }
                if (paramEntity.IsNotNullOrEmpty() && paramEntity.PART_NO.IsNotNullOrEmpty())
                {
                    lstEntity = (from row in DB.WORK_ORDER_MAIN
                                 where row.PART_NO == paramEntity.PART_NO && row.WORK_ORDER_NO == paramEntity.WORK_ORDER_NO
                                 select row).ToList <WORK_ORDER_MAIN>();
                }
                else
                {
                    lstEntity = (from row in DB.WORK_ORDER_MAIN
                                 select row).ToList <WORK_ORDER_MAIN>();
                }
            }
            catch (Exception ex)
            {
                ex.LogException();
            }

            return(lstEntity);
        }
        public bool Delete <T>(List <T> entities)
        {
            bool returnValue = (!entities.IsNotNullOrEmpty() || (entities.IsNotNullOrEmpty() && entities.Count == 0 ? true : false));

            foreach (T entity in entities)
            {
                if ((entity as WORK_ORDER_MAIN).IsNotNullOrEmpty())
                {
                    WORK_ORDER_MAIN obj          = null;
                    WORK_ORDER_MAIN activeEntity = (entity as WORK_ORDER_MAIN);
                    try
                    {
                        obj = (from row in DB.WORK_ORDER_MAIN
                               where row.IDPK == activeEntity.IDPK
                               select row).SingleOrDefault <WORK_ORDER_MAIN>();
                        if (obj.IsNotNullOrEmpty())
                        {
                            obj.DELETE_FLAG  = true;
                            obj.UPDATED_BY   = userInformation.UserName;
                            obj.UPDATED_DATE = serverDateTime;
                            DB.SubmitChanges();

                            ChangeSet cs = DB.GetChangeSet();
                            returnValue = cs.Updates.Count > 0 ? true : false;
                            returnValue = true;
                        }
                    }
                    catch (ChangeConflictException)
                    {
                        foreach (ObjectChangeConflict conflict in DB.ChangeConflicts)
                        {
                            conflict.Resolve(RefreshMode.KeepChanges);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.LogException();
                        DB.WORK_ORDER_MAIN.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, obj);
                    }
                }
                if ((entity as OQA_CCF).IsNotNullOrEmpty())
                {
                    OQA_CCF objChild          = null;
                    OQA_CCF activeEntityChild = (entity as OQA_CCF);
                    try
                    {
                        objChild = (from row in DB.OQA_CCF
                                    where row.IDPK == activeEntityChild.IDPK
                                    select row).SingleOrDefault <OQA_CCF>();

                        if (objChild.IsNotNullOrEmpty())
                        {
                            DB.OQA_CCF.DeleteOnSubmit(objChild);
                            DB.SubmitChanges();

                            ChangeSet cs = DB.GetChangeSet();
                            returnValue = cs.Deletes.Count > 0 ? true : false;
                            returnValue = true;
                        }
                    }
                    catch (ChangeConflictException)
                    {
                        foreach (ObjectChangeConflict conflict in DB.ChangeConflicts)
                        {
                            conflict.Resolve(RefreshMode.KeepChanges);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.LogException();
                        DB.OQA_CCF.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, objChild);
                    }
                }
            }
            return(returnValue);
        }
        public bool Update <T>(List <T> entities)
        {
            bool returnValue = false;

            foreach (T entity in entities)
            {
                if ((entity as WORK_ORDER_MAIN).IsNotNullOrEmpty())
                {
                    WORK_ORDER_MAIN obj          = null;
                    WORK_ORDER_MAIN activeEntity = (entity as WORK_ORDER_MAIN);

                    obj = (from row in DB.WORK_ORDER_MAIN
                           where row.IDPK == activeEntity.IDPK
                           select row).SingleOrDefault <WORK_ORDER_MAIN>();
                    if (obj.IsNotNullOrEmpty())
                    {
                        try
                        {
                            obj.WORK_ORDER_NO = activeEntity.WORK_ORDER_NO;
                            obj.PART_NO       = activeEntity.PART_NO;
                            obj.TOTAL_QTY     = activeEntity.TOTAL_QTY;
                            obj.PART_DESC     = activeEntity.PART_DESC;
                            obj.CCF           = activeEntity.CCF;
                            obj.ROWID         = activeEntity.ROWID;

                            obj.DELETE_FLAG  = false;
                            obj.UPDATED_BY   = userInformation.UserName;
                            obj.UPDATED_DATE = serverDateTime;
                            DB.SubmitChanges();

                            ChangeSet cs = DB.GetChangeSet();
                            returnValue = cs.Updates.Count > 0 ? true : false;
                            returnValue = true;
                        }
                        catch (ChangeConflictException)
                        {
                            foreach (ObjectChangeConflict conflict in DB.ChangeConflicts)
                            {
                                conflict.Resolve(RefreshMode.KeepChanges);
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.LogException();
                            DB.WORK_ORDER_MAIN.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, obj);
                        }
                    }
                    else
                    {
                        returnValue = Delete <WORK_ORDER_MAIN>(new List <WORK_ORDER_MAIN> {
                            activeEntity
                        });
                        returnValue = Insert <WORK_ORDER_MAIN>(new List <WORK_ORDER_MAIN> {
                            activeEntity
                        });
                    }
                }
                if ((entity as OQA_CCF).IsNotNullOrEmpty())
                {
                    OQA_CCF objChild          = null;
                    OQA_CCF activeEntityChild = (entity as OQA_CCF);

                    objChild = (from row in DB.OQA_CCF
                                where row.IDPK == activeEntityChild.IDPK
                                select row).SingleOrDefault <OQA_CCF>();

                    if (objChild.IsNotNullOrEmpty())
                    {
                        try
                        {
                            objChild.PART_NO = activeEntityChild.PART_NO;
                            objChild.CCF     = activeEntityChild.CCF;
                            objChild.IDPK    = activeEntityChild.IDPK;

                            objChild.DELETE_FLAG  = false;
                            objChild.ENTERED_DATE = activeEntityChild.ENTERED_DATE;
                            objChild.ENTERED_BY   = activeEntityChild.ENTERED_BY;
                            objChild.UPDATED_DATE = serverDateTime;
                            objChild.UPDATED_BY   = userInformation.UserName;

                            DB.SubmitChanges();

                            ChangeSet cs = DB.GetChangeSet();
                            returnValue = cs.Updates.Count > 0 ? true : false;
                            returnValue = true;
                        }
                        catch (ChangeConflictException)
                        {
                            foreach (ObjectChangeConflict conflict in DB.ChangeConflicts)
                            {
                                conflict.Resolve(RefreshMode.KeepChanges);
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.LogException();
                            DB.OQA_CCF.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, objChild);
                        }
                        returnValue = true;
                    }
                    else
                    {
                        returnValue = Delete <OQA_CCF>(new List <OQA_CCF> {
                            activeEntityChild
                        });
                        returnValue = Insert <OQA_CCF>(new List <OQA_CCF> {
                            activeEntityChild
                        });
                    }
                    returnValue = true;
                }
            }
            returnValue = true;
            return(returnValue);
        }
        public bool Insert <T>(List <T> entities)
        {
            bool returnValue = false;

            foreach (T entity in entities)
            {
                if ((entity as WORK_ORDER_MAIN).IsNotNullOrEmpty())
                {
                    WORK_ORDER_MAIN obj = entity as WORK_ORDER_MAIN;
                    try
                    {
                        if (obj.IDPK <= 0)
                        {
                            obj.IDPK = GenerateNextNumber("WORK_ORDER_MAIN", "IDPK").ToIntValue();
                        }

                        obj.ROWID        = Guid.NewGuid();
                        obj.DELETE_FLAG  = false;
                        obj.ENTERED_BY   = userName;
                        obj.ENTERED_DATE = serverDateTime;

                        DB.WORK_ORDER_MAIN.InsertOnSubmit(obj);
                        DB.SubmitChanges();

                        ChangeSet cs = DB.GetChangeSet();
                        returnValue = cs.Inserts.Count > 0 ? true : false;
                    }
                    catch (ChangeConflictException)
                    {
                        foreach (ObjectChangeConflict conflict in DB.ChangeConflicts)
                        {
                            conflict.Resolve(RefreshMode.KeepChanges);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.LogException();
                        DB.WORK_ORDER_MAIN.DeleteOnSubmit(obj);
                    }
                }
                if ((entity as OQA_CCF).IsNotNullOrEmpty())
                {
                    OQA_CCF obj = entity as OQA_CCF;
                    try
                    {
                        if (obj.IDPK <= 0)
                        {
                            obj.IDPK = GenerateNextNumber("OQA_CCF", "IDPK").ToIntValue();
                        }
                        DB.OQA_CCF.InsertOnSubmit(obj);
                        DB.SubmitChanges();

                        ChangeSet cs = DB.GetChangeSet();
                        returnValue = cs.Inserts.Count > 0 ? true : false;
                    }
                    catch (InvalidOperationException)
                    {
                        DB.OQA_CCF.DeleteOnSubmit(obj);
                        DB.SubmitChanges();
                    }
                    catch (ChangeConflictException)
                    {
                        foreach (ObjectChangeConflict conflict in DB.ChangeConflicts)
                        {
                            conflict.Resolve(RefreshMode.KeepChanges);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.LogException();
                        DB.OQA_CCF.DeleteOnSubmit(obj);
                    }
                }
            }

            returnValue = true;
            return(returnValue);
        }