Example #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            var    obj             = JObject.Load(reader);
            string inputTypeString = (string)obj.SelectToken("InputType");

            if (!String.IsNullOrWhiteSpace(inputTypeString))
            {
                TextGeneratorInputType inputType = (TextGeneratorInputType)Enum.Parse(typeof(TextGeneratorInputType), inputTypeString);
                //Log.Here().Activity($"inputType: {inputType.ToString()}");

                if (inputType == TextGeneratorInputType.Incremental || inputType == TextGeneratorInputType.Decremental)
                {
                    TextGeneratorInputNumberData target = new TextGeneratorInputNumberData();

                    var jObjectReader = CreateNewReader(reader, obj);
                    serializer.Populate(jObjectReader, target);
                    target.InputType = inputType;

                    //Log.Here().Activity($"Created input: {target.GetType().ToString()} | {target.Keyword} | {target.IncrementBy}");

                    return(target);
                }
                else if (inputType == TextGeneratorInputType.Text)
                {
                    TextGeneratorInputTextData target = new TextGeneratorInputTextData();

                    var jObjectReader = CreateNewReader(reader, obj);
                    serializer.Populate(jObjectReader, target);
                    target.InputType = inputType;

                    return(target);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                TextGeneratorViewModel vm = new TextGeneratorViewModel();
                var jObjectReader         = CreateNewReader(reader, obj);
                serializer.Populate(jObjectReader, vm);
                return(vm);
            }
        }
Example #2
0
        // GET: TextGenerator
        public ActionResult Index()
        {
            // Validate log in and user access
            UserAccessSession UASession = (UserAccessSession)Session["UserAccess"];

            if (UASession == null || !UASession.TEG)
            {
                return(RedirectToAction("Login", "Account"));
            }

            Session["CurrentPage"] = new CurrentPageSession("TEG", "HOME", "LOG");
            TextGeneratorViewModel TGViewModel = new TextGeneratorViewModel();

            TGViewModel.IncludeAll = true;
            return(View(TGViewModel));
        }
Example #3
0
        public ActionResult Index(TextGeneratorViewModel TGViewModel)
        {
            TextGeneratorManager TGManager = new TextGeneratorManager();
            ReportViewModel      report    = TGManager.GeneratePackets(TGViewModel);
            bool   result     = report.Result;
            string PageAction = "Text Generation";

            if (result)
            {
                TempData["SuccessMessage"] = PageAction + " successful. Key: " + report.Message;
            }
            else
            {
                TempData["ErrorMessage"] = PageAction + " failed";
            }
            return(View(new TextGeneratorViewModel()));
        }
Example #4
0
 public void InitData()
 {
     Data = new TextGeneratorViewModel();
 }
Example #5
0
        /*
         * Generates text from database
         */
        public ReportViewModel GeneratePackets(TextGeneratorViewModel TGViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                ReportViewModel report = new ReportViewModel();
                string          key    = GenerateKey();
                report.Message = key;

                for (int i = 0; i < TGViewModel.StoreList.Count(); i++)
                {
                    if (TGViewModel.StoreList[i].Cb || TGViewModel.IncludeAllStores)
                    {
                        // Data creation
                        MemoryStream  ms             = new MemoryStream();
                        StreamWriter  sb             = new StreamWriter(ms);
                        TextGenerator tg             = new TextGenerator();
                        string        Store_No       = TGViewModel.StoreList[i].value;
                        string        Store_Name     = TGViewModel.StoreList[i].text;
                        string        DateAndTimeNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        DateTime      DateFrom       = DateTime.Parse(TGViewModel.DateFrom);
                        DateTime      DateTo         = DateTime.Parse(TGViewModel.DateTo);

                        // Append first line
                        sb.Write("01," + Store_No + "," + Store_Name + "," + DateAndTimeNow + "," + TGViewModel.PromoTitle + "\n");

                        if (TGViewModel.IncludeMIM || TGViewModel.IncludeAll)
                        {
                            List <CSHMIMP0> MIRows = GetMenutems(Store_No, DateFrom, DateTo);
                            foreach (CSHMIMP0 mi in MIRows)
                            {
                                sb.Write(tg.GenerateMenuItemMasterText(mi));
                                mi.STATUS = "0";
                            }
                        }
                        if (TGViewModel.IncludeRIM || TGViewModel.IncludeAll)
                        {
                            List <INVRIMP0> RIRows = GetRawItems(Store_No, DateFrom, DateTo);
                            foreach (INVRIMP0 ri in RIRows)
                            {
                                sb.Write(tg.GenerateRawItemMasterText(ri));
                                ri.STATUS = "0";
                            }
                        }
                        if (TGViewModel.IncludeREC || TGViewModel.IncludeAll)
                        {
                            List <INVRIRP0> RERows = GetRecipes(Store_No, DateFrom, DateTo);
                            foreach (INVRIRP0 re in RERows)
                            {
                                sb.Write(tg.GenerateRecipeText(re));
                                re.STATUS = "0";
                            }
                        }

                        List <CSHVMLP0> VMRows = GetValueMeal(Store_No, DateFrom, DateTo);
                        foreach (CSHVMLP0 vm in VMRows)
                        {
                            sb.Write(tg.GenerateValueMealText(vm));
                            vm.STATUS = "0";
                        }

                        List <CSHPMGP0> PMGRows = GetProductMixGroup(Store_No, DateFrom, DateTo);
                        foreach (CSHPMGP0 pmg in PMGRows)
                        {
                            sb.Write(tg.GenerateProductMixText(pmg));
                            pmg.STATUS = "0";
                        }

                        List <INVMGRP0> MGRows = GetMaterialGroup(Store_No, DateFrom, DateTo);
                        foreach (INVMGRP0 mg in MGRows)
                        {
                            sb.Write(tg.GenerateMaterialGroupText(mg));
                            mg.STATUS = "0";
                        }
                        List <INVUOMP0> UOMRows = GetUnitOfMeasure(Store_No, DateFrom, DateTo);
                        foreach (INVUOMP0 uom in UOMRows)
                        {
                            sb.Write(tg.GenerateInitOfMeasureText(uom));
                            uom.STATUS = "0";
                        }
                        List <INVVEMP0> VERows = GetVendor(Store_No, DateFrom, DateTo);
                        foreach (INVVEMP0 ve in VERows)
                        {
                            sb.Write(tg.GenerateVendorText(ve));
                            ve.STATUS = "0";
                        }
                        // File creation
                        //  *Used for file name
                        string PaddedStore_No = TGViewModel.StoreList[i].value;
                        int    len            = PaddedStore_No.Length;
                        for (int j = 0; j < (5 - len); j++)
                        {
                            PaddedStore_No = "0" + PaddedStore_No;
                        }
                        string filename = "CFM" + PaddedStore_No + "_" + DateTime.Now.ToString("MMddyyyy_HHmm");
                        if (TGViewModel.IncludeAll)
                        {
                            filename += ".ALL";
                        }
                        else
                        {
                            filename += ".PRO";
                        }
                        string path = @"C:/SMS/SMSWEBCFM/";

                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }

                        FileStream file = new FileStream(path + "e" + filename, FileMode.Create, FileAccess.ReadWrite);
                        ms.WriteTo(file);
                        file.Close();
                        ms.Close();
                        EncryptText(path + "e" + filename, path + filename, key);
                        File.Delete(path + "e" + filename);

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine(e.Source);
                            System.Diagnostics.Debug.WriteLine(e.Message);
                            System.Diagnostics.Debug.WriteLine(e.StackTrace);
                            System.Diagnostics.Debug.WriteLine(e.InnerException);
                            Exception f = e.InnerException;
                            while (f != null)
                            {
                                System.Diagnostics.Debug.WriteLine("INNER:");
                                System.Diagnostics.Debug.WriteLine(f.Message);
                                System.Diagnostics.Debug.WriteLine(f.Source);
                                f = f.InnerException;
                            }
                            System.Diagnostics.Debug.WriteLine(e.Data);
                        }
                    }
                }
                return(report);
            }
        }
 public TextGeneratorPage()
 {
     this.InitializeComponent();
     ViewModel = Locator.Instance.TextGenerate;
 }