public int ManageDuplicateUndeliveredPurchase()
        {
            int rowFocusindex = -1;

            //ShowAllCount = PSDetailsEntity.Where(e => e.SelectedPSID != 0).Count();
            TempList = new ObservableCollection <UndeliveredPurchaseOrdersDepositsGridViewModel>();
            TempList = UndeliveredPurchaseOrdersDepositsDetailsEntity;

            var query = TempList.GroupBy(x => x.ID)
                        .Where(g => g.Count() > 1)
                        .ToList();

            if (query.Count > 0 && UndeliveredPurchaseOrdersDepositsDetailsEntity.Count > 1)
            {
                var obj1 = query[0].ElementAt(0);
                var obj2 = query[0].ElementAt(1);
                int?qty  = 1;

                qty = query[0].ElementAt(0).CountQty + query[0].ElementAt(1).CountQty;

                var index1 = TempList.IndexOf(query[0].ElementAt(0));
                var index2 = TempList.IndexOf(query[0].ElementAt(1));
                OnPropertyChanged("UndeliveredPurchaseOrdersDepositsDetailsEntity");
                TempList = UndeliveredPurchaseOrdersDepositsDetailsEntity;
            }
            else
            {
                int count = UndeliveredPurchaseOrdersDepositsDetailsEntity.Count(x => x.ID == 0);
                if (count == 0)
                {
                    var row = new UndeliveredPurchaseOrdersDepositsGridViewModel(UndeliveredPurchaseList);
                    // row.CountQty = 0;
                    //   row.GSTRate = TaxRate;

                    UndeliveredPurchaseOrdersDepositsDetailsEntity.Add(row);
                    OnPropertyChanged("UndeliveredPurchaseOrdersDepositsDetailsEntity");
                    TempList      = UndeliveredPurchaseOrdersDepositsDetailsEntity;
                    rowFocusindex = -1;
                }
                else
                {
                    var emptyRow = TempList.Where(y => y.ID == 0).FirstOrDefault();
                    rowFocusindex = UndeliveredPurchaseOrdersDepositsDetailsEntity.IndexOf(emptyRow);
                }
            }
            return(rowFocusindex);
        }
        public void createNewUndeliveredPurchase()
        {
            var row = new UndeliveredPurchaseOrdersDepositsGridViewModel(UndeliveredPurchaseList);

            //row.SelectedPSID = 0;
            if (UndeliveredPurchaseOrdersDepositsDetailsEntity != null)
            {
                if (UndeliveredPurchaseOrdersDepositsDetailsEntity.Count > 0)
                {
                    UndeliveredPurchaseOrdersDepositsDetailsEntity.Clear();
                    // var row = new CollectAmountDataGridViewModel();
                    //  PQDetailsEntity.Add(row);
                    OnPropertyChanged("UndeliveredPurchaseOrdersDepositsDetailsEntity");
                }
            }
            UndeliveredPurchaseOrdersDepositsDetailsEntity.Add(row);
            OnPropertyChanged("UndeliveredPurchaseOrdersDepositsDetailsEntity");
        }
        public bool CanSave(object param)
        {
            string msg    = string.Empty;
            bool   status = false;
            var    list1  = UndeliveredPurchaseOrdersDepositsDetailsEntity.Where(x => x.ID == null).ToList();
            var    list   = UndeliveredPurchaseOrdersDepositsDetailsEntity.Except(list1);

            foreach (var item in list)
            {
                var   date          = item.OrderDate;
                var   Customer      = item.ID;
                var   OrderNo       = item.OrderNo;
                var   UpdatedAmount = item.UndeliveredAmount;
                var   DipositAmount = item.DepositAmount;
                Regex r             = new Regex("");
                if (date != null && Customer != null && OrderNo != null && UpdatedAmount != null && DipositAmount != null)
                {
                    Regex number = new Regex("^[0-9]*$");

                    //Regex r = new Regex("^(((0[1-9]|[12][0-9]|30)[-/]?(0[13-9]|1[012])|31[-/]?(0[13578]|1[02])|(0[1-9]|1[0-9]|2[0-8])[-/]?02)[-/]?[0-9]{4}|29[-/]?02[-/]?([0-9]{2}(([2468][048]|[02468][48])|[13579][26])|([13579][26]|[02468][048]|0[0-9]|1[0-6])00))$");
                    // Regex r = new Regex("^(((0[1-9]|[12][0-9]|3[01])[-/]?(0[13578]|1[02])[-/]?([0-9]{2}))|((0[1-9]|[12][0-9]|30)[-/]?(0[13456789]|1[012])[-/]?([0-9]{2}))|((0[1-9]|1[0-9]|2[0-8])[-/]?02[-/]?([0-9]{2}))|(29[-/]?02[-/]?((0[48]|[2468][048]|[13579][26])|(00))))$");
                    // Regex r = new Regex("^((0[1-9])|(1[0-2]))[-/]?((0[1-9])|(1[0-9])|(2[0-9])|(3[0-1]))[-/]?(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))$");
                    if (DateFormat == "dd/MM/yy")
                    {
                        r = new Regex("^(((0[1-9]|[12][0-9]|3[01])[-/](0[13578]|1[02])[-/]([0-9]{2}))|((0[1-9]|[12][0-9]|30)[-/](0[13456789]|1[012])[-/]([0-9]{2}))|((0[1-9]|1[0-9]|2[0-8])[-/]02[-/]([0-9]{2}))|(29[-/]02[-/]((0[48]|[2468][048]|[13579][26])|(00))))$");
                    }
                    if (DateFormat == "MM/dd/yy")
                    {
                        r = new Regex("^((0[1-9])|(1[0-2]))[-/]((0[1-9])|([0-2][1-9])|(3[0-1])|(20)|(10))[-/](([0-9][1-9])|([1-9]0))$");
                    }
                    if (DateFormat == "yy/MM/dd")
                    {
                        r = new Regex("^((([0-9][1-9])|([1-9]0))[-/]((0[1-9])|(1[0-2]))[-/]((0[1-9])|([0-2][1-9])|(3[0-1])|(20)|(10)))$");
                    }
                    if (number.IsMatch(OrderNo))
                    {
                        msg             = "";
                        this.DateErrors = msg;
                        var no = number.IsMatch(OrderNo);
                        if (Convert.ToInt32(no) > 0)
                        {
                            msg             = "";
                            this.DateErrors = msg;
                            if (r.IsMatch(date))
                            {
                                msg             = "";
                                this.DateErrors = msg;
                                // status = true;
                            }
                            else
                            {
                                msg             = "Only Date Accepted";
                                this.DateErrors = msg;
                                status          = false;
                                break;
                            }
                        }
                        else
                        {
                            msg             = "Positive Number Accepted";
                            this.DateErrors = msg;
                            status          = false;
                            break;
                        }
                    }
                    else
                    {
                        msg             = "Only Numbers Accepted";
                        this.DateErrors = msg;
                        status          = false;
                        break;
                    }
                    status = true;
                }
                else
                {
                    status = false;
                }
            }
            return(status);
        }