Пример #1
0
        /// <summary>
        /// 保存为JSON文件
        /// </summary>
        /// <param name="CoverJson">写入JSON文件,默认 false</param>
        /// <returns></returns>
        public ActionResultVM SaveAsJson(bool CoverJson = false)
        {
            var vm = new ActionResultVM();

            var dicKey = new Dictionary <string, object>
            {
                { "SysButton", Tsb.ToList() },
                { "SysDictionary", Tsd.ToList() },
                { "SysMenu", Tsm.ToList() },
                { "SysRole", Tsr.ToList() },
                { "SysTableConfig", Tstc.ToList() },
                { "SysUser", Tsu.ToList() },

                { "TempExample", Tte.ToList() },
                { "TempInvoiceDetail", Ttid.ToList() },
                { "TempInvoiceMain", Ttim.ToList() }
            };

            vm.data = dicKey;

            if (CoverJson)
            {
                Core.FileTo.WriteText(vm.ToJson(), JsonPath, JsonName, false);
            }

            vm.Set(ARTag.success);

            return(vm);
        }
Пример #2
0
        /// <summary>
        /// The button accept on click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ButtonAcceptOnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.TextBoxTteName.Text) ||
                string.IsNullOrWhiteSpace(this.TextBoxTteEmailId.Text) ||
                string.IsNullOrWhiteSpace(this.PasswordBoxTtePassword.Password) ||
                string.IsNullOrWhiteSpace(this.ComboBoxZoneName.Text) ||
                string.IsNullOrWhiteSpace(this.ComboBoxDivisionName.Text))
            {
                MessageBox.Show("Please fill up all the fields!");
                return;
            }

            if (!this.TextBoxTteName.Text.Contains(" "))
            {
                if (MessageBox.Show(
                        $"Is \"{this.TextBoxTteName.Text}\" Full Name of the TTE?",
                        "Confirmation of Full Name",
                        MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }
            }

            ButtonProgressAssist.SetIsIndicatorVisible(this.ButtonAccept, true);

            var tte = new Tte
            {
                Name     = this.TextBoxTteName.Text,
                EmailId  = this.TextBoxTteEmailId.Text,
                Password = this.PasswordBoxTtePassword.Password,
                Zone     = this.ComboBoxZoneName.Text,
                Division = this.ComboBoxDivisionName.Text
            };

            var backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += (o, args) =>
            {
                var task = this.AddTteAsync(tte);

                Task.WaitAll(task);
            };
            backgroundWorker.RunWorkerCompleted += (o, args) =>
            {
                MessageBox.Show("You have successfully added TTE" + $"\nName: {this.TextBoxTteName.Text}\nId: {this.tteId}");
                ButtonProgressAssist.SetIsIndicatorVisible(this.ButtonAccept, false);
            };

            try
            {
                backgroundWorker.RunWorkerAsync();
                this.Refresh();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// 根据JSON写入数据
        /// </summary>
        /// <param name="isClear">是否清理表,默认清理</param>
        /// <returns></returns>
        public int AddForJson(bool isClear = true)
        {
            var json = Core.FileTo.ReadText(JsonPath, JsonName);

            var objs = json.ToJObject()["data"];

            var jsb  = objs["SysButton"].ToString().ToEntitys <SysButton>();
            var jsd  = objs["SysDictionary"].ToString().ToEntitys <SysDictionary>();
            var jsm  = objs["SysMenu"].ToString().ToEntitys <SysMenu>();
            var jsr  = objs["SysRole"].ToString().ToEntitys <SysRole>();
            var jstc = objs["SysTableConfig"].ToString().ToEntitys <SysTableConfig>();
            var jsu  = objs["SysUser"].ToString().ToEntitys <SysUser>();
            var jte  = objs["TempExample"].ToString().ToEntitys <TempExample>();
            var jtid = objs["TempInvoiceDetail"].ToString().ToEntitys <TempInvoiceDetail>();
            var jtim = objs["TempInvoiceMain"].ToString().ToEntitys <TempInvoiceMain>();

            Tsb  = Cdb.SysButton;
            Tsd  = Cdb.SysDictionary;
            Tsm  = Cdb.SysMenu;
            Tsr  = Cdb.SysRole;
            Tstc = Cdb.SysTableConfig;
            Tsu  = Cdb.SysUser;
            Tte  = Cdb.TempExample;
            Ttid = Cdb.TempInvoiceDetail;
            Ttim = Cdb.TempInvoiceMain;

            var num = 0;

            if (isClear)
            {
                Tsb.RemoveRange(Tsb.ToList());
                Tsd.RemoveRange(Tsd.ToList());
                Tsm.RemoveRange(Tsm.ToList());
                Tsr.RemoveRange(Tsr.ToList());
                Tstc.RemoveRange(Tstc.ToList());
                Tsu.RemoveRange(Tsu.ToList());

                Tte.RemoveRange(Tte.ToList());
                Ttid.RemoveRange(Ttid.ToList());
                Ttim.RemoveRange(Ttim.ToList());

                num = Cdb.SaveChanges();
            }

            Tsb.AddRange(jsb);
            Tsd.AddRange(jsd);
            Tsm.AddRange(jsm);
            Tsr.AddRange(jsr);
            Tstc.AddRange(jstc);
            Tsu.AddRange(jsu);

            Tte.AddRange(jte);
            Ttid.AddRange(jtid);
            Ttim.AddRange(jtim);

            Cdb.AddRange(jsb);

            num += Cdb.SaveChanges();

            return(num);
        }
Пример #4
0
        /// <summary>
        /// The Add TTE async.
        /// </summary>
        /// <param name="tte">
        /// The TTE
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task AddTteAsync(Tte tte)
        {
            var id = StaticDbContext.ConnectFireStore.GetAllDocumentId(
                "Root",
                "Employee",
                tte.Zone,
                tte.Division,
                "Tte");

            var max = 0;

            if (id.Count != 0)
            {
                max = Convert.ToInt32(id.OrderByDescending(i => int.Parse(i.Substring(8))).First().Substring(8));
            }

            this.tteId = $"{(int)EnumEmployeeGroups.GroupB:D2}" +
                         $"{(int)EnumEmployeeType.Tte:D2}" +
                         $"{DataHelper.ZoneAndDivisionModel.ZoneList.IndexOf(tte.Zone):D2}" +
                         $"{DataHelper.ZoneAndDivisionModel.DivisionList[tte.Zone].IndexOf(tte.Division):D2}" +
                         $"{max + 1:D7}";

            tte.Id = this.tteId;

            var noOfTte = 0;

            var divisionField =
                StaticDbContext.ConnectFireStore.GetCollectionFields("Root", "Employee", tte.Zone, tte.Division);

            if (divisionField != null)
            {
                noOfTte = Convert.ToInt32(divisionField["noOfTte"]);
            }

            if (StaticDbContext.ConnectFireStore?.FindDocument(
                    tte.Id,
                    "Root",
                    "Employee",
                    tte.Zone,
                    tte.Division,
                    "Tte") == false)
            {
                noOfTte++;
            }

            await StaticDbContext.ConnectFireStore.AddOrUpdateCollectionDataAsync(
                new Dictionary <string, int> {
                { "noOfTte", noOfTte }
            },
                "Root",
                "Employee",
                tte.Zone,
                tte.Division);

            await StaticDbContext.ConnectFireStore.AddOrUpdateCollectionDataAsync(
                tte,
                "Root",
                "Employee",
                tte.Zone,
                tte.Division,
                "Tte",
                tte.Id);
        }
Пример #5
0
        /// <summary>
        /// The background worker do work.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private async void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            var tteName  = string.Empty;
            var zone     = string.Empty;
            var division = string.Empty;

            this.Dispatcher.Invoke(
                () =>
            {
                ButtonProgressAssist.SetIsIndicatorVisible(this.ButtonAccept, true);
                tteName  = this.TextBoxTteName.Text;
                zone     = this.ComboBoxZoneName.Text;
                division = this.ComboBoxDivisionName.Text;
            },
                DispatcherPriority.Normal);

            var id = StaticDbContext.ConnectFireStore.GetAllDocumentId(
                "Root",
                "Employee",
                zone,
                division,
                "Tte");

            var max = 0;

            if (id.Count != 0)
            {
                max = Convert.ToInt32(id.OrderByDescending(i => int.Parse(i.Substring(8))).First().Substring(8));
            }

            this.tteId = $"{(int)EnumEmployeeGroups.GroupB:D2}" +
                         $"{(int)EnumEmployeeType.Tte:D2}" +
                         $"{DataHelper.ZoneAndDivisionModel.ZoneList.IndexOf(zone):D2}" +
                         $"{DataHelper.ZoneAndDivisionModel.DivisionList[zone].IndexOf(division):D2}" +
                         $"{(max + 1):D7}";

            var tte = new Tte
            {
                Name = tteName,
                Id   = this.tteId
            };

            var noOfTte = 0;

            var divisionField =
                StaticDbContext.ConnectFireStore.GetCollectionFields("Root", "Employee", zone, division);

            if (divisionField != null)
            {
                noOfTte = Convert.ToInt32(divisionField["noOfTte"]);
            }

            noOfTte++;

            await StaticDbContext.ConnectFireStore.AddOrUpdateCollectionDataAsync(
                new Dictionary <string, int> {
                { "noOfTte", noOfTte }
            },
                "Root",
                "Employee",
                zone,
                division);

            await StaticDbContext.ConnectFireStore.AddOrUpdateCollectionDataAsync(
                tte,
                "Root",
                "Employee",
                zone,
                division,
                "Tte",
                tte.Id);
        }
Пример #6
0
        /// <summary>
        /// 根据JSON写入数据
        /// </summary>
        /// <param name="isClear">是否清理表,默认清理</param>
        /// <returns></returns>
        public ActionResultVM AddForJson(bool isClear = true)
        {
            var vm = new ActionResultVM();

            try
            {
                var json = Core.FileTo.ReadText(fullJsonData);

                var objs = json.ToJObject()["data"];

                var jsb  = objs["SysButton"].ToString().ToEntitys <SysButton>();
                var jsd  = objs["SysDictionary"].ToString().ToEntitys <SysDictionary>();
                var jsm  = objs["SysMenu"].ToString().ToEntitys <SysMenu>();
                var jsr  = objs["SysRole"].ToString().ToEntitys <SysRole>();
                var jstc = objs["SysTableConfig"].ToString().ToEntitys <SysTableConfig>();
                var jsu  = objs["SysUser"].ToString().ToEntitys <SysUser>();
                var jte  = objs["TempExample"].ToString().ToEntitys <TempExample>();
                var jtid = objs["TempInvoiceDetail"].ToString().ToEntitys <TempInvoiceDetail>();
                var jtim = objs["TempInvoiceMain"].ToString().ToEntitys <TempInvoiceMain>();

                using var db = ContextBaseFactory.CreateDbContext();

                Tsb  = db.SysButton;
                Tsd  = db.SysDictionary;
                Tsm  = db.SysMenu;
                Tsr  = db.SysRole;
                Tstc = db.SysTableConfig;
                Tsu  = db.SysUser;
                Tte  = db.TempExample;
                Ttid = db.TempInvoiceDetail;
                Ttim = db.TempInvoiceMain;

                var num = 0;
                if (isClear)
                {
                    Tsb.RemoveRange(Tsb.ToList());
                    Tsd.RemoveRange(Tsd.ToList());
                    Tsm.RemoveRange(Tsm.ToList());
                    Tsr.RemoveRange(Tsr.ToList());
                    Tstc.RemoveRange(Tstc.ToList());
                    Tsu.RemoveRange(Tsu.ToList());

                    Tte.RemoveRange(Tte.ToList());
                    Ttid.RemoveRange(Ttid.ToList());
                    Ttim.RemoveRange(Ttim.ToList());

                    num = db.SaveChanges();
                }

                Tsb.AddRange(jsb);
                Tsd.AddRange(jsd);
                Tsm.AddRange(jsm);
                Tsr.AddRange(jsr);
                Tstc.AddRange(jstc);
                Tsu.AddRange(jsu);

                Tte.AddRange(jte);
                Ttid.AddRange(jtid);
                Ttim.AddRange(jtim);

                db.AddRange(jsb);

                num += db.SaveChanges();

                vm.Set(num > 0);
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }