public ActionResult Index(bool _isdraft, string _language, string _partid)
        {
            ViewData["NoResultMessage"] = "";
            string part = _partid != null ? _partid : "";

            ViewData["PartID"] = part;
            var viewModel = new TravelCardPrintViewModel
            {
                ItemID  = "",
                IsDraft = _isdraft,

                PartSetUp          = _partsetupRepository.PartSetUp.FirstOrDefault(a => a.PartID.Trim() == part),
                NumContinuationTCs = 0
            };

            viewModel.TravelCards = _travelcardRepository.TravelCard.Where(a => a.PartSetUpID == viewModel.PartSetUp.PartSetUpID);
            DateTime curdate        = DateTime.Now;
            DateTime oldtcardlookup = curdate.AddDays(-60);

            viewModel.PartSpecifications = _partspecificationRepository.PartSpecification.Where(a => a.PartSetUpID == viewModel.PartSetUp.PartSetUpID);
            var filteredcards = viewModel.TravelCards
                                .Where(c => c.PrintDate > oldtcardlookup)
                                .Where(c => c.IsContinuationCard == false);

            filteredcards = filteredcards.Where(a => a.TCBarCodeText != "0");
            filteredcards = filteredcards.Where(a => a.TCBarCodeText != "");

            viewModel.TravelCards = filteredcards;
            var opcodelist = (from p in viewModel.PartSpecifications.Where(c => c.OperationCode != null).Select(a => a.OperationCode).OrderBy(c => c.Value).Distinct()
                              select new SelectListItem

            {
                Text = p.Value.ToString(), Value = p.Value.ToString()
            });


            ViewData["opcodelist"] = opcodelist;

            if (opcodelist != null && opcodelist.Count() > 0)
            {
                viewModel.HasOpCodes = true;
            }
            var printorientation = viewModel.PrintOrientationSelectList;

            ViewData["printorientation"] = printorientation;

            string selectedlanguage = _language;

            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(selectedlanguage);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedlanguage);
            viewModel.Language = selectedlanguage;


            return(View("Index", viewModel));
        }
        public void TravelCardPrint()

        {
            TravelCardPrintViewModel viewModel = new TravelCardPrintViewModel

            {
            };
            var    partsetup   = viewModel.PartSetUp.Where(q => q.PartID == this.partid);
            string partsetupid = partsetup.Select(a => a.PartSetUpID).ToString();

            partid = partid.Trim();
            string workpdffilepath = System.Configuration.ConfigurationManager.AppSettings["pdfWorkFilePath"].ToString();
            string filename        = workpdffilepath + partsetupid.Trim() + ".pdf";
        }
        public int SaveTravelCards(TravelCardPrintViewModel viewModel,
                                   bool isdraft, int?operationcode, int partsetupid, bool iscontinuationcard)
        {
            GetUserInfo();
            string user     = username;
            string language = ResolveCulture().Name;

            viewModel.TCLanguage  = _languageRepository.Language.FirstOrDefault(a => a.LanguageCode == language.Trim());
            viewModel.UserSetting = _usersettingsRepository.UserSetting.FirstOrDefault(a => a.UserName == username);
            viewModel.PartSetUp   = _partsetupRepository.PartSetUp.FirstOrDefault(a => a.PartSetUpID == partsetupid);
            //TODO: Find out why I had to declare a new TravelCard since it was included in the view model.
            TravelCard.DomainModel.Entities.TravelCard travelcard_ = new TravelCard.DomainModel.Entities.TravelCard();

            //save the travel card record

            int travelcardID = 0;

            travelcard_.PartSetUpID        = viewModel.PartSetUp.PartSetUpID;
            travelcard_.IsContinuationCard = iscontinuationcard;
            travelcard_.LanguageID         = Convert.ToInt16(viewModel.TCLanguage.LanguageID);
            travelcard_.IsDraft            = isdraft;
            travelcard_.OperationCode      = Convert.ToInt16(operationcode);
            travelcard_.PrintDate          = DateTime.Now;
            travelcard_.PrintedBy          = username;
            travelcard_.PrintLocation      = viewModel.UserSetting.Plant.PlantName;
            travelcard_.Notes = "";
            travelcardID      = _travelcardRepository.Insert(travelcard_);



            //save the bar code text;
            string plantnum  = viewModel.UserSetting.Plant.PlantCode;
            string partsetup = viewModel.PartSetUp.PartSetUpID.ToString();
            string tcid      = travelcardID.ToString();
            string barcodeid = plantnum + "-" + partsetup + "-" + tcid;

            viewModel.TravelCard = _travelcardRepository.TravelCard.FirstOrDefault(a => a.TCID == travelcardID);
            viewModel.TravelCard.TCBarCodeText = barcodeid;
            _travelcardRepository.Update(viewModel.TravelCard);



            return(travelcardID);
        }
        public ActionResult IndexReturn(bool _isdraft, string _language, string _partid)
        {
            string part = _partid != null ? _partid : "";

            ViewData["PartID"] = part;
            var viewModel = new TravelCardPrintViewModel
            {
                ItemID  = "",
                IsDraft = _isdraft,
            };

            string selectedlanguage = _language;

            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(selectedlanguage);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedlanguage);
            viewModel.Language          = selectedlanguage;
            ViewData["NoResultMessage"] = Quality.Resources.Strings.PartNumPlease;

            return(View("Index", viewModel));
        }
        public ActionResult BackToIndex(TravelCardPrintViewModel _viewModel)
        {
            ///

            ViewData["NoResultMessage"] = "";
            ViewData["PartID"]          = "";
            var viewModel = new TravelCardPrintViewModel
            {
                ItemID  = _viewModel.PartSetUp.PartID,
                IsDraft = _viewModel.IsDraft,
            };

            string selectedlanguage = _viewModel.Language;

            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(selectedlanguage);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedlanguage);
            viewModel.Language = selectedlanguage;


            return(View("Index", viewModel));
        }
        public ActionResult TCContinuationBarCodeDisplay(TravelCardPrintViewModel viewModel, string barcodetext, int?opcode, int thispartsetupid, bool isdraft, bool iscontinuationcard, string id, bool showText = true, int thickness = 3, int height = 70)
        {
            //first save the travel card record, need the travel card id from the database to build the barcode.
            int    travelcardid      = SaveContinuationTravelCards(viewModel, barcodetext, isdraft, opcode, thispartsetupid, iscontinuationcard);
            string travelcardidvalue = travelcardid.ToString();

            //mow save the bar code with the
            string barcodesavepath = ConfigurationManager.AppSettings["BarCodeSavePath"];
            string filepath        = barcodesavepath;
            var    barcode         = new Code39BarCode()
            {
                BarCodeText     = barcodetext,
                Height          = height,
                ShowBarCodeText = showText
            };

            if (thickness == 2)
            {
                barcode.BarCodeWeight = BarCodeWeight.Medium;
            }
            else if (thickness == 3)
            {
                barcode.BarCodeWeight = BarCodeWeight.Large;
            }

            id = id + "-" + travelcardid;
            ImageResult result = this.Image(barcode.Generate(), "image/gif", id, filepath);
            //added this hack because the users in mexico were having the travel card display prior to the bar codes being written.


            string BarcodeFilePath = filepath + id + ".gif";


            Session["tcbarcodepath"] = BarcodeFilePath;
            string thissession = Convert.ToString(Session["tcbarcodepath"]);

            Session["barcodetext"] = id;
            return(result);
        }
        public ActionResult TravelCard(TravelCardPrintViewModel _viewModel, FormCollection result)
        {
            string ItemID  = _viewModel.ItemID;
            string message = "";
            string partid  = "";

            string operationcode = "";


            foreach (var key in result.AllKeys)
            {
                if (key.Contains("OperationCodes"))
                {
                    operationcode = operationcode + result.Get(key);
                }
            }

            GetUserInfo();
            string name = username.ToLower();



            if (String.IsNullOrEmpty(ItemID))
            {
                ModelState.AddModelError("PartSearchError", "Please enter a part number");
            }
            if (ModelState["TravelCard.TCID"] != null)
            {
                ModelState["TravelCard.TCID"].Errors.Clear();
            }
            if (ModelState.IsValid)
            {
                bool isdraft = _viewModel.IsDraft;
                ItemID = _viewModel.ItemID.ToUpper();
                // int partsetupid = _viewModel.PartSetUp.PartSetUpID;

                partid = ItemID.Trim();
                int numofcards = _viewModel.NumContinuationTCs;
                int?opcode     = operationcode != ""?Convert.ToInt16(operationcode):0;
                _viewModel.PartSetUp = _partsetupRepository.PartSetUp.FirstOrDefault(a => a.PartID == partid);

                int thispartsetupid = _viewModel.PartSetUp.PartSetUpID;



                TravelCardPrintViewModel viewModel = new TravelCardPrintViewModel()
                {
                    PartSetUp   = _partsetupRepository.PartSetUp.FirstOrDefault(x => x.PartID == partid),
                    PartSetUpID = _partsetupRepository.PartSetUp.Where(x => x.PartID == partid).Select(a => a.PartSetUpID).FirstOrDefault(),

                    NumContinuationTCs = numofcards,
                    IsDraft            = _viewModel.IsDraft,
                    UsersCulture       = ResolveCulture(),


                    UserSetting = _usersettingRepository.UserSetting.FirstOrDefault(a => a.UserName == name),
                };



                if (_viewModel.TravelCard != null)
                {
                    viewModel.TravelCard = _travelcardRepository.TravelCard.FirstOrDefault(a => a.TCID == _viewModel.TravelCard.TCID);
                }



                if (viewModel.TravelCard != null)
                {
                    viewModel.ContinuationBarCodeText = viewModel.TravelCard.TCBarCodeText;
                }

                viewModel.Plant = _plantRepository.Plant.FirstOrDefault(a => a.PlantCodeID == viewModel.UserSetting.PlantCodeID);
                string plant = viewModel.Plant.PlantCode;
                viewModel.Component = _componentsRepository.GetByID(partid, plant);
                viewModel.Part      = _partsRepository.GetByID(partid, plant);

                string selectedlanguage = _viewModel.Language;
                if (selectedlanguage != null)
                {
                    Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(selectedlanguage);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedlanguage);
                    viewModel.UsersCulture = Thread.CurrentThread.CurrentCulture;
                }


                if (viewModel.Part.Count() > 0 && viewModel.PartSetUp == null)
                {
                    message = "Part #" + partid + " was found in the ASI but the part has not been set up in the Travel Card system. Please contact Product Engineering.";

                    ViewData["NoResultMessage"] = message;
                    ViewData["PartID"]          = partid;
                    return(View("Index", viewModel));
                }

                if (viewModel.Part.Count() == 0 && viewModel.PartSetUp == null)
                {
                    message = "Part #" + partid + " was not found in ASI . Please please try again.";

                    ViewData["NoResultMessage"] = message;
                    ViewData["PartID"]          = partid;
                    return(View("Index", viewModel));
                }



                var partsetupid = viewModel.PartSetUpID;
                IEnumerable <Component> subcomponents = _componentsRepository.GetByID(partid, plant);
                List <int> subcomponentpartsetupids   = new List <int>();
                foreach (string partno in subcomponents.Select(a => a.Id))
                {
                    partno.ToString().Trim();
                    var partsetupidofsubcomponents = _partsetupRepository.PartSetUp.FirstOrDefault(a => a.PartID == partno);
                    if (partsetupidofsubcomponents != null)
                    {
                        subcomponentpartsetupids.Add(partsetupidofsubcomponents.PartSetUpID);
                    }
                }



                if (operationcode.Length > 0)
                {
                    int opcodenum = Convert.ToInt16(operationcode);
                    viewModel.OpCode             = opcodenum;
                    viewModel.PartSpecifications = _partspecificationRepository.PartSpecification.Where(a => a.PartSetUpID == partsetupid)
                                                   .Where(b => b.IsPartCharacteristic == true)
                                                   .Where(c => c.IsPartCharacteristic == true).OrderBy(c => c.SequenceID);
                    viewModel.PartSpecifications = viewModel.PartSpecifications.Where(a => a.OperationCode == opcodenum);
                }
                else
                {
                    viewModel.PartSpecifications = _partspecificationRepository.PartSpecification.Where(a => a.PartSetUpID == partsetupid)
                                                   .Where(b => b.IsPartCharacteristic == true)
                                                   .Where(c => c.IsPartCharacteristic == true).OrderBy(c => c.SequenceID);
                }

                foreach (var setupid in subcomponentpartsetupids)
                {
                    viewModel.ComponentPartSpecifications = _componentpartspecificationRepository.PartSpecification.Where(a => a.PartSetUpID == setupid)
                                                            .Where(c => c.IsComponentCharacteristic == true).OrderBy(c => c.SequenceID);
                }



                viewModel.AdditionalProcesses        = _additionalprocessesRepository.AdditionalProcess.Where(a => a.PartSetUpID == partsetupid).Where(b => b.IsActive == true).OrderBy(c => c.SequenceID);
                viewModel.MeasurementMethods         = _measurementmethodRepository.MeasurementMethod;
                viewModel.MeasurementUnits           = _measurementunitRepository.MeasurementUnit;
                viewModel.PartSpecificationSequences = _partspecificationsequenceRepository.PartSpecificationSequence;
                viewModel.Frequencies = _frequencyRepository.Frequency.Where(a => a.IsActive);



                bool isreleaseready = viewModel.PartSetUp.IsReleaseReady;
                // bool isactive = viewModel.PartSetUp.PartIsActive;


                message = "";



                if ((isreleaseready == false && viewModel.PartSetUp != null) && (isdraft == false))
                {
                    message = "Part #" + partid + " was found in ASI but the part set up has not been set as release ready in the Travel Card System. Please contact Product Engineering.";

                    ViewData["NoResultMessage"] = message;
                    ViewData["PartID"]          = partid;
                    return(View("Index", viewModel));
                }



                if (viewModel.Part.Count() == 0)
                {
                    message = "Part not found in the system. Please try again.";
                    ViewData["NoResultMessage"] = message;
                    ViewData["PartID"]          = partid;
                    return(View("Index", viewModel));
                }


                return(View("TravelCardPrint", viewModel));
            }
            else
            {
                ViewData["NoResultMessage"] = "";
                ViewData["PartID"]          = "";
                var viewModel = new TravelCardPrintViewModel
                {
                    ItemID       = "",
                    IsDraft      = _viewModel.IsDraft,
                    UsersCulture = ResolveCulture()
                };

                bool   isdraft  = _viewModel.IsDraft;
                string language = _viewModel.Language;
                viewModel.PartSpecifications = viewModel.PartSpecifications.Where(a => a.IsActive);

                return(View("TravelCardPrint", viewModel));
            }
        }