Esempio n. 1
0
        private void project_Changed()
        {
            List <project_template_detail> _projectTemplate = new List <project_template_detail>();
            int selectid = Convert.ToInt32(id_project);

            _projectTemplate = entity.db.project_template_detail.Where(x => x.id_project_template == selectid).ToList();
            project_template_detail accesories_template       = _projectTemplate.Where(x => x.logic == "Accessory").FirstOrDefault();
            project_template_detail accesories_x_qty_template = _projectTemplate.Where(x => x.logic == "Accessory Per Quantity").FirstOrDefault();
            project_template_detail ink_template     = _projectTemplate.Where(x => x.logic == "ink").FirstOrDefault();
            project_template_detail printer_template = _projectTemplate.Where(x => x.logic == "printer").FirstOrDefault();
            project_template_detail toner_template   = _projectTemplate.Where(x => x.logic == "Toner").FirstOrDefault();
            project_template_detail paper_template   = _projectTemplate.Where(x => x.logic == "paper").FirstOrDefault();
            project_template_detail cut_template     = _projectTemplate.Where(x => x.logic == "Cut").FirstOrDefault();

            //project_template_detail accesory_abc = _projectTemplate.Where(x => x.logic == "accesory_abc").FirstOrDefault();

            if (ink_template != null)
            {
                int _inkTag = Convert.ToInt16(ink_template.id_tag);

                cmbink.SelectedValuePath = "id_item";
                cmbink.DisplayMemberPath = "name";
                cmbink.ItemsSource       = entity.db.items
                                           .Where(x => entity.db.item_tag_detail.Where(y => y.id_tag == _inkTag)
                                                  .Select(z => z.id_item)
                                                  .Contains(x.id_item)).ToList();
                cmbvalue.ItemsSource = ink_Percentage;
            }

            if (printer_template != null)
            {
                _printerTag = Convert.ToInt16(printer_template.id_tag);

                using (db db = new db())
                {
                    List <item> printerlist = entity.db.items.Where(x => entity.db.item_tag_detail
                                                                    .Where(y => y.id_tag == _printerTag)
                                                                    .Select(z => z.id_item)
                                                                    .Contains(x.id_item)).ToList();

                    foreach (item _item in printerlist)
                    {
                        PrintingPress.Printer _printer = new PrintingPress.Printer();
                        _printer.Id          = _item.id_item;
                        _printer.Name        = _item.name;
                        _printer.Min_Long    = (decimal)_item.item_asset.FirstOrDefault().min_width;
                        _printer.Min_Short   = (decimal)_item.item_asset.FirstOrDefault().min_length;
                        _printer.Max_Long    = (decimal)_item.item_asset.FirstOrDefault().max_width;
                        _printer.Max_Short   = (decimal)_item.item_asset.FirstOrDefault().max_length;
                        _printer.Speed       = (int)_item.item_asset.FirstOrDefault().speed;
                        _printer.Color_Limit = (int)_item.item_property.FirstOrDefault().value;
                        _printer.Cost        = (decimal)_item.unit_cost;
                        _printer.Cost_DieSet = (decimal)_item.item_asset.FirstOrDefault().dieset_price;
                        //Adding to List
                        _printerList.Add(_printer);
                        //stpprinter.ItemsSource = _printerList;
                    }
                }
            }

            if (accesories_template != null)
            {
                int         _accessoryTag = Convert.ToInt16(accesories_template.id_tag);
                List <item> _itemList     = entity.db.items.Where(x => entity.db.item_tag_detail
                                                                  .Where(y => y.id_tag == _accessoryTag)
                                                                  .Select(z => z.id_item).Contains(x.id_item)).ToList();

                foreach (item item in _itemList)
                {
                    int id_item = Convert.ToInt32(item.id_item);
                    if (id_item > 0)
                    {
                        PrintingPress.Accessory accessory = new PrintingPress.Accessory();
                        accessory.Id          = (int)item.id_item;
                        accessory.Cost        = (decimal)item.unit_cost;
                        accessory.Name        = item.name;
                        accessory.Consumption = 1;
                        accessory.Calc_Cost   = accessory.Cost * accessory.Consumption;
                        _accessoryList.Add(accessory);
                    }
                }
                itemaccesories.ItemsSource = _accessoryList.ToList();
            }

            if (toner_template != null)
            {
                int  _tonerTag = Convert.ToInt16(toner_template.id_tag);
                item _toner    = entity.db.items
                                 .Where(x => entity.db.item_tag_detail
                                        .Where(y => y.id_tag == _tonerTag)
                                        .Select(z => z.id_item).Contains(x.id_item)).FirstOrDefault();
            }

            if (cut_template != null)
            {
                int  _cutTag = Convert.ToInt16(cut_template.id_tag);
                item _cut    = entity.db.items
                               .Where(x => entity.db.item_tag_detail
                                      .Where(y => y.id_tag == _cutTag)
                                      .Select(z => z.id_item).Contains(x.id_item)).FirstOrDefault();
            }

            if (paper_template != null)
            {
                int _paperTag = Convert.ToInt16(paper_template.id_tag);
                using (db db = new db())
                {
                    List <item> paperlist = entity.db.items
                                            .Where(x => entity.db.item_tag_detail.Where(y => y.id_tag == _paperTag)
                                                   .Select(z => z.id_item)
                                                   .Contains(x.id_item)).ToList();

                    foreach (item _item in paperlist)
                    {
                        PrintingPress.Paper _paper = new PrintingPress.Paper();
                        _paper.Id = _item.id_item;

                        if (_item.item_dimension.Where(x => x.id_app_dimension == id_Weight).FirstOrDefault() != null)
                        {
                            _paper.Weight = (int)_item.item_dimension.Where(x => x.id_app_dimension == id_Weight).FirstOrDefault().value;
                        }
                        else
                        {
                            _paper.Weight = 0;
                        }

                        _paper.Cost = (decimal)_item.unit_cost;

                        if (_item.item_dimension.Where(x => x.id_app_dimension == id_Long).FirstOrDefault() != null)
                        {
                            _paper.Long = (decimal)_item.item_dimension.Where(x => x.id_app_dimension == id_Long).FirstOrDefault().value;
                        }
                        else
                        {
                            _paper.Long = 0;
                        }

                        if (_item.item_dimension.Where(x => x.id_app_dimension == id_Short).FirstOrDefault() != null)
                        {
                            _paper.Short = (decimal)_item.item_dimension.Where(x => x.id_app_dimension == id_Short).FirstOrDefault().value;
                        }
                        else
                        {
                            _paper.Short = 0;
                        }

                        _paper.Name = _paper.Long.ToString() + " x " + _paper.Short.ToString();
                        //Adding Paper to PaperList
                        _paperList.Add(_paper);
                    }
                }
            }
        }
Esempio n. 2
0
        private PrintingPress.calc_Cost return_Cost
            (PrintingPress.Product _product,
            PrintingPress.Paper _paper,
            PrintingPress.Printer printer,
            decimal _page_Long,
            decimal _page_Short)
        {
            List <PrintingPress.calc_Cost> _calc_CostList = new List <PrintingPress.calc_Cost>();

            PrintingPress.Paper papertt = new PrintingPress.Paper();
            papertt.Cost       = _paper.Cost;
            papertt.Id         = _paper.Id;
            papertt.IsSelected = _paper.IsSelected;
            papertt.Long       = _paper.Long;
            papertt.Name       = _paper.Name;
            papertt.Qty        = _paper.Qty;
            papertt.Qty_Fit    = _paper.Qty_Fit;
            papertt.Short      = _paper.Short;
            papertt.Weight     = _paper.Weight;

            PrintingPress.Printer Printertt = new PrintingPress.Printer();
            Printertt.Color_Limit = printer.Color_Limit;
            Printertt.Cost        = printer.Cost;
            Printertt.Cost_DieSet = printer.Cost_DieSet;
            Printertt.Id          = printer.Id;
            Printertt.IsSelected  = printer.IsSelected;
            Printertt.Max_Long    = printer.Max_Long;
            Printertt.Max_Short   = printer.Max_Short;
            Printertt.Min_Long    = printer.Min_Long;
            Printertt.Min_Short   = printer.Min_Short;
            Printertt.Name        = printer.Name;
            Printertt.Runs        = printer.Runs;
            Printertt.Speed       = printer.Speed;
            Printertt.Time        = printer.Time;

            //True True
            PrintingPress.calc_Cost calc_Cost_TT = new PrintingPress.calc_Cost();
            calc_Cost_TT._printer = Printertt;
            calc_Cost_TT._product = _product;
            calc_Cost_TT._toner   = _toner;

            calc_Cost_TT._paper      = papertt; //_paperList.Where(x => x.IsSelected).FirstOrDefault();
            calc_Cost_TT._page       = new PrintingPress.Page();
            calc_Cost_TT._page.Long  = _page_Long;
            calc_Cost_TT._page.Short = _page_Short;
            calc_Cost_TT.calc_Automatic(ref _inkList, ref _accessoryList, true, true);
            if (calc_Cost_TT._paper.Qty_Fit >= 1)
            {
                _calc_CostList.Add(calc_Cost_TT);
            }
            PrintingPress.Paper papertf = new PrintingPress.Paper();
            papertf.Cost       = _paper.Cost;
            papertf.Id         = _paper.Id;
            papertf.IsSelected = _paper.IsSelected;
            papertf.Long       = _paper.Long;
            papertf.Name       = _paper.Name;
            papertf.Qty        = _paper.Qty;
            papertf.Qty_Fit    = _paper.Qty_Fit;
            papertf.Short      = _paper.Short;
            papertf.Weight     = _paper.Weight;

            PrintingPress.Printer Printertf = new PrintingPress.Printer();
            Printertf.Color_Limit = printer.Color_Limit;
            Printertf.Cost        = printer.Cost;
            Printertf.Cost_DieSet = printer.Cost_DieSet;
            Printertf.Id          = printer.Id;
            Printertf.IsSelected  = printer.IsSelected;
            Printertf.Max_Long    = printer.Max_Long;
            Printertf.Max_Short   = printer.Max_Short;
            Printertf.Min_Long    = printer.Min_Long;
            Printertf.Min_Short   = printer.Min_Short;
            Printertf.Name        = printer.Name;
            Printertf.Runs        = printer.Runs;
            Printertf.Speed       = printer.Speed;
            Printertf.Time        = printer.Time;

            //True False
            PrintingPress.calc_Cost calc_Cost_TF = new PrintingPress.calc_Cost();
            calc_Cost_TF._printer = Printertf;
            calc_Cost_TF._product = _product;
            calc_Cost_TF._toner   = _toner;

            calc_Cost_TF._paper      = papertf; //_paperList.Where(x => x.IsSelected).FirstOrDefault();
            calc_Cost_TF._page       = new PrintingPress.Page();
            calc_Cost_TF._page.Long  = _page_Long;
            calc_Cost_TF._page.Short = _page_Short;
            calc_Cost_TF.calc_Automatic(ref _inkList, ref _accessoryList, true, false);
            if (calc_Cost_TF._paper.Qty_Fit >= 1)
            {
                _calc_CostList.Add(calc_Cost_TF);
            }
            PrintingPress.Paper paperft = new PrintingPress.Paper();
            paperft.Cost       = _paper.Cost;
            paperft.Id         = _paper.Id;
            paperft.IsSelected = _paper.IsSelected;
            paperft.Long       = _paper.Long;
            paperft.Name       = _paper.Name;
            paperft.Qty        = _paper.Qty;
            paperft.Qty_Fit    = _paper.Qty_Fit;
            paperft.Short      = _paper.Short;
            paperft.Weight     = _paper.Weight;


            PrintingPress.Printer Printerft = new PrintingPress.Printer();
            Printerft.Color_Limit = printer.Color_Limit;
            Printerft.Cost        = printer.Cost;
            Printerft.Cost_DieSet = printer.Cost_DieSet;
            Printerft.Id          = printer.Id;
            Printerft.IsSelected  = printer.IsSelected;
            Printerft.Max_Long    = printer.Max_Long;
            Printerft.Max_Short   = printer.Max_Short;
            Printerft.Min_Long    = printer.Min_Long;
            Printerft.Min_Short   = printer.Min_Short;
            Printerft.Name        = printer.Name;
            Printerft.Runs        = printer.Runs;
            Printerft.Speed       = printer.Speed;
            Printerft.Time        = printer.Time;

            //False True
            PrintingPress.calc_Cost calc_Cost_FT = new PrintingPress.calc_Cost();
            calc_Cost_FT._printer = Printerft;
            calc_Cost_FT._product = _product;
            calc_Cost_FT._toner   = _toner;

            calc_Cost_FT._paper      = paperft; //_paperList.Where(x => x.IsSelected).FirstOrDefault();
            calc_Cost_FT._page       = new PrintingPress.Page();
            calc_Cost_FT._page.Long  = _page_Long;
            calc_Cost_FT._page.Short = _page_Short;
            calc_Cost_FT.calc_Automatic(ref _inkList, ref _accessoryList, false, true);
            if (calc_Cost_FT._paper.Qty_Fit >= 1)
            {
                _calc_CostList.Add(calc_Cost_FT);
            }
            PrintingPress.Paper paperff = new PrintingPress.Paper();
            paperff.Cost       = _paper.Cost;
            paperff.Id         = _paper.Id;
            paperff.IsSelected = _paper.IsSelected;
            paperff.Long       = _paper.Long;
            paperff.Name       = _paper.Name;
            paperff.Qty        = _paper.Qty;
            paperff.Qty_Fit    = _paper.Qty_Fit;
            paperff.Short      = _paper.Short;
            paperff.Weight     = _paper.Weight;

            PrintingPress.Printer Printerff = new PrintingPress.Printer();
            Printerff.Color_Limit = printer.Color_Limit;
            Printerff.Cost        = printer.Cost;
            Printerff.Cost_DieSet = printer.Cost_DieSet;
            Printerff.Id          = printer.Id;
            Printerff.IsSelected  = printer.IsSelected;
            Printerff.Max_Long    = printer.Max_Long;
            Printerff.Max_Short   = printer.Max_Short;
            Printerff.Min_Long    = printer.Min_Long;
            Printerff.Min_Short   = printer.Min_Short;
            Printerff.Name        = printer.Name;
            Printerff.Runs        = printer.Runs;
            Printerff.Speed       = printer.Speed;
            Printerff.Time        = printer.Time;

            //False False
            PrintingPress.calc_Cost calc_Cost_FF = new PrintingPress.calc_Cost();
            calc_Cost_FF._printer = Printerff;
            calc_Cost_FF._product = _product;
            calc_Cost_FF._toner   = _toner;

            calc_Cost_FF._paper      = paperff; //_paperList.Where(x => x.IsSelected).FirstOrDefault();
            calc_Cost_FF._page       = new PrintingPress.Page();
            calc_Cost_FF._page.Long  = _page_Long;
            calc_Cost_FF._page.Short = _page_Short;
            calc_Cost_FF.calc_Automatic(ref _inkList, ref _accessoryList, false, false);
            if (calc_Cost_FF._paper.Qty_Fit >= 1)
            {
                _calc_CostList.Add(calc_Cost_FF);
            }

            //Returning Cheapest
            if (_calc_CostList.Count > 0)
            {
                return(_calc_CostList.OrderBy(x => x.cost).First());
            }
            else
            {
                return(null);
            }
        }