Пример #1
0
        public void LoadData()
        {
            try
            {
                LogisticsList.Clear();
                LogisticsListService.Clear();
                if (projectViewSource != null)
                {
                    item_ProductDataGrid.ItemsSource = null;
                    item_RawDataGrid.ItemsSource     = null;
                    item_ServiceDataGrid.ItemsSource = null;
                    item_CapitalDataGrid.ItemsSource = null;
                    dgvSupplies.ItemsSource          = null;

                    int _id_project = 0;
                    if (projectViewSource.View.CurrentItem != null)
                    {
                        _id_project = ((project)projectViewSource.View.CurrentItem).id_project;
                    }

                    if (_id_project > 0)
                    {
                        var productlistbasic = (from IT in ProjectTaskDB.project_task
                                                where (IT.status == Status.Project.Approved || IT.status == Status.Project.InProcess) &&
                                                IT.status != null && IT.id_project == _id_project
                                                join IK in ProjectTaskDB.item_product on IT.id_item equals IK.id_item
                                                //join PTD in ProjectTaskDB.purchase_tender_detail on IT.id_project_task equals PTD.purchase_tender_item.id_project_task into a
                                                //from IM in a.DefaultIfEmpty()
                                                group IT by new { IT.items }
                                                into last
                                                select new
                        {
                            _id_item = last.Key.items.id_item != 0 ? last.Key.items.id_item : 0,
                            _code = last.Key.items != null ? last.Key.items.code : "",
                            _name = last.Key.items != null ? last.Key.items.name : "",
                            _id_task = last.Max(x => x.id_project_task),
                            _ordered_quantity = last.Sum(x => x.quantity_est) != 0 ? last.Sum(x => x.quantity_est) : 0,
                            //avlqtyColumn = last.Key.IM.quantity,
                            //buyqty = (last.Sum(x => x.quantity_est) != 0 ? last.Sum(x => x.quantity_est) : 0) - (last.Key.IM.quantity != 0 ? last.Key.IM.quantity : 0),
                            item = last.Key.items
                        }).ToList();



                        var productlist = (from PL in productlistbasic
                                           group PL by new { PL.item }
                                           into last
                                           select new
                        {
                            _id_item = last.Key.item.id_item != 0 ? last.Key.item.id_item : 0,
                            _code = last.Key.item != null ? last.Key.item.code : "",
                            _name = last.Key.item != null ? last.Key.item.name : "",
                            _id_task = last.Max(x => x._id_task),
                            _ordered_quantity = last.Max(x => x._ordered_quantity),
                            //avlqtyColumn = last.Sum(x => x.avlqtyColumn),
                            //buyqty = last.Sum(x => x.avlqtyColumn) < last.Max(x => x._ordered_quantity) ? (last.Max(x => x._ordered_quantity) != 0 ? last.Max(x => x._ordered_quantity) : 0) - (last.Sum(x => x.avlqtyColumn) != 0 ? last.Sum(x => x.avlqtyColumn) : 0) : 0,
                            item = last.Key.item
                        }).ToList();

                        foreach (dynamic item in productlist)
                        {
                            int      id_task   = (int)item._id_task;
                            Logistic Logistics = new Logistic();
                            if (ProjectTaskDB.project_task.Where(x => x.id_project_task == id_task).FirstOrDefault() != null)
                            {
                                project_task project_task = ProjectTaskDB.project_task.Where(x => x.id_project_task == id_task).FirstOrDefault();
                                Logistics.avlqtyColumn = project_task.purchase_tender_item.Sum(x => x.quantity);
                                Logistics.buyqty       = (decimal)item._ordered_quantity - (decimal)project_task.purchase_tender_item.Sum(x => x.quantity);
                            }


                            Logistics._id_item          = item._id_item;
                            Logistics._code             = item._code;
                            Logistics._name             = item._name;
                            Logistics._id_task          = item._id_task;
                            Logistics._ordered_quantity = item._ordered_quantity;
                            Logistics.item = item.item;
                            LogisticsList.Add(Logistics);
                        }

                        item_ProductDataGrid.ItemsSource = LogisticsList.Where(IT => IT.item.id_item_type == item.item_type.Product).ToList();

                        item_RawDataGrid.ItemsSource = LogisticsList.Where(IT => IT.item.id_item_type == item.item_type.RawMaterial).ToList();
                        var servicelist = (from IT in ProjectTaskDB.project_task
                                           where IT.status == Status.Project.Approved &&
                                           IT.status != null && IT.id_project == _id_project

                                           group IT by new { IT.items } into last
                                           select new
                        {
                            _id_item = last.Key.items.id_item != 0 ? last.Key.items.id_item : 0,
                            _code = last.Key.items != null ? last.Key.items.code : "",
                            _name = last.Key.items != null ? last.Key.items.name : "",
                            _id_task = last.Max(x => x.id_project_task),
                            _ordered_quantity = last.Sum(x => x.quantity_est) != 0 ? last.Sum(x => x.quantity_est) : 0,
                            item = last.Key.items
                        }).ToList();

                        foreach (dynamic item in servicelist)
                        {
                            Logistic Logistics = new Logistic();
                            Logistics._id_item = item._id_item;
                            Logistics._code    = item._code;
                            Logistics._name    = item._name;
                            Logistics._id_task = item._id_task;
                            if (item._ordered_quantity == null)
                            {
                                Logistics._ordered_quantity = 0;
                            }
                            else
                            {
                                Logistics._ordered_quantity = item._ordered_quantity;
                            }

                            Logistics.item = item.item;
                            LogisticsListService.Add(Logistics);
                        }
                        item_ServiceDataGrid.ItemsSource = LogisticsListService.Where(IT => IT.item.id_item_type == item.item_type.Service).ToList();
                        item_CapitalDataGrid.ItemsSource = LogisticsListService.Where(IT => IT.item.id_item_type == item.item_type.FixedAssets).ToList();
                        dgvServiceContract.ItemsSource   = LogisticsListService.Where(IT => IT.item.id_item_type == item.item_type.ServiceContract).ToList();

                        dgvSupplies.ItemsSource = LogisticsListService.Where(IT => IT.item.id_item_type == item.item_type.Supplies).ToList();;
                    }
                }

                //Clears out values until Logistic is selected.
                project_taskViewSource = ((CollectionViewSource)(this.FindResource("project_taskViewSource")));
                if (project_taskViewSource != null)
                {
                    //Bad code to clear out ViewSource. I did this to avoid an error.
                    List <project_task> list = ProjectTaskDB.project_task.Where(IT => IT.id_company == 999).ToList();
                    project_taskViewSource.Source = list;
                }
            }
            catch //(Exception ex)
            {
                //Do thing to avoid error showing for small reasons.
            }
        }
Пример #2
0
        private void chkqtyneeded_Checked(object sender, RoutedEventArgs e)
        {
            LogisticsList.Clear();
            project project    = ((project)projectViewSource.View.CurrentItem);
            int     id_project = ((project)projectViewSource.View.CurrentItem).id_project;

            if (id_project > 0)
            {
                if (chkqtyneeded.IsChecked == true)
                {
                    //  buyqty.Visibility = System.Windows.Visibility.Collapsed;
                    var item_List_group_basic = (from IT in ProjectTaskDB.project_task
                                                 where (IT.status == Status.Project.Approved || IT.status == Status.Project.InProcess) &&
                                                 IT.status != null && IT.id_project == id_project
                                                 join IK in ProjectTaskDB.item_product on IT.id_item equals IK.id_item
                                                 join IO in ProjectTaskDB.item_movement on IK.id_item_product equals IO.id_item_product into a
                                                 from IM in a.DefaultIfEmpty()
                                                 group IT by new { IT.items, IM }
                                                 into last
                                                 select new
                    {
                        _id_item = last.Key.items.id_item != 0 ? last.Key.items.id_item : 0,
                        _code = last.Key.items != null ? last.Key.items.code : "",
                        _name = last.Key.items != null ? last.Key.items.name : "",
                        _id_task = last.Max(x => x.id_project_task),
                        _ordered_quantity = last.Sum(x => x.quantity_est) != 0 ? last.Sum(x => x.quantity_est) : 0,
                        avlqtyColumn = last.Key.IM.credit - last.Key.IM.debit,
                        buyqty = (last.Sum(x => x.quantity_est) != 0 ? last.Sum(x => x.quantity_est) : 0) - (last.Key.IM.credit != null ? last.Key.IM.credit : 0 - last.Key.IM.debit != null ? last.Key.IM.debit : 0),
                        item = last.Key.items
                    }).ToList();

                    var item_List_group = (from PL in item_List_group_basic
                                           group PL by new { PL.item }
                                           into last
                                           select new
                    {
                        _id_item = last.Key.item.id_item != 0 ? last.Key.item.id_item : 0,
                        _code = last.Key.item != null ? last.Key.item.code : "",
                        _name = last.Key.item != null ? last.Key.item.name : "",
                        _id_task = last.Max(x => x._id_task),
                        _ordered_quantity = last.Max(x => x._ordered_quantity),
                        avlqtyColumn = last.Sum(x => x.avlqtyColumn),
                        buyqty = last.Sum(x => x.avlqtyColumn) < last.Max(x => x._ordered_quantity) ? (last.Max(x => x._ordered_quantity) != 0 ? last.Max(x => x._ordered_quantity) : 0) - (last.Sum(x => x.avlqtyColumn) != 0 ? last.Sum(x => x.avlqtyColumn) : 0) : 0,
                        item = last.Key.item
                    }).ToList();


                    foreach (dynamic item in item_List_group)
                    {
                        int      id_task   = (int)item._id_task;
                        Logistic Logistics = new Logistic();

                        Logistics.avlqtyColumn      = item.avlqtyColumn;
                        Logistics.buyqty            = item.buyqty;
                        Logistics._id_item          = item._id_item;
                        Logistics._code             = item._code;
                        Logistics._name             = item._name;
                        Logistics._id_task          = item._id_task;
                        Logistics._ordered_quantity = item._ordered_quantity;
                        Logistics.item = item.item;
                        LogisticsList.Add(Logistics);
                    }
                    item_ProductDataGrid.ItemsSource = LogisticsList.Where(x => x.item.id_item_type == item.item_type.Product);
                    item_RawDataGrid.ItemsSource     = LogisticsList.Where(x => x.item.id_item_type == item.item_type.RawMaterial);
                }
            }
        }