Ejemplo n.º 1
0
        /// <summary>
        /// Read Json data
        /// </summary>
        /// <param name="path">Json file path</param>
        /// <returns></returns>
        public static TabPageAll ReadJson_TabNames(string path)
        {
            Logger.Debug("开始读取Json文件 " + "文件名:" + path);
            TabPageAll obj = null;

            string jsonStr = File.ReadAllText(path);

            if (!string.IsNullOrEmpty(jsonStr))
            {
                try
                {
                    obj = JsonConvert.DeserializeObject <TabPageAll>(jsonStr);
                }
                catch (Exception e)
                {
                    Logger.Error(e.ToString());
                }
            }
            else
            {
                Logger.Debug("Json文件:null");
            }
            //using (StreamReader sr = new StreamReader(path))
            //{
            //    JsonTextReader reader = new JsonTextReader(sr);
            //    if (reader.LineNumber != 0)
            //    {
            //        jObj = (JObject)JToken.ReadFrom(reader);
            //    }
            //}
            Logger.Debug("结束读取Json文件");
            return(obj);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存tabPage的名字
        /// </summary>
        public bool WriteJsonTabPageNames(string tabPageName, TabPageAll tabPageAll)
        {
            Logger.Debug("[保存tabPage的名字] 执行开始");
            // 读取json数据存入tpnList里
            try
            {
                TabPageAll obj = JsonAccess.ReadJson_TabNames(path);
                if (obj != null)
                {
                    foreach (TabPageNames item in obj.TabPageNames)
                    {
                        TabPageNames tpn1 = new TabPageNames();
                        tpn1.Name = item.Name;
                        tabPageAll.TabPageNames.Add(tpn1);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.ToString());
                return(false);
            }

            int cnt = 0;

            if (tabPageAll != null && tabPageAll.TabPageNames.Count > 0)
            {
                cnt = (from tpn in tabPageAll.TabPageNames
                       where tpn.Name == tabPageName
                       select tpn).Count();
            }

            if (cnt > 0)
            {
                MessageBox.Show("类别名称已存在!");
                return(false);
            }
            // 声明TabPageNames
            TabPageNames tpn2 = new TabPageNames();

            tpn2.Name = tabPageName;       // 画面传来在name
                                           // 添加到tpnList里
            tabPageAll.TabPageNames.Add(tpn2);

            // 写入json
            JsonAccess.WriteJson(path, tabPageAll);

            // 如果添加在名字存在

            Logger.Debug("[保存tabPage的名字] 执行终了");
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加类别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txt_add_Click(object sender, EventArgs e)
        {
            Logger.Debug("[添加类别] 执行开始");
            string text = txt_typeName.Text;

            if (string.IsNullOrEmpty(text))
            {
                MessageBox.Show("请输入类别名称!");
                return;
            }

            // 写入json
            TabPageNameAccess tpnAccess = new TabPageNameAccess();

            GetJsonPath(JsonFileName);

            TabPage tabPage     = new TabPage();
            string  tabPageName = "tp_" + text;

            tabPage.Name = tabPageName;
            tabPage.Text = text;

            // 写入Json
            tpnAccess.GetPath(JsonPath);
            TabPageAll tabPageAll = new TabPageAll();
            bool       result     = tpnAccess.WriteJsonTabPageNames(tabPageName, tabPageAll);

            if (result)
            {
                tabC_ctx.TabPages.Clear();
                foreach (TabPageNames item in tabPageAll.TabPageNames)
                {
                    Logger.Debug("开始添加Tab:" + item.Name.Remove(0, 3));
                    tabC_ctx.TabPages.Add(item.Name.Remove(0, 3));
                }
            }
            // 添加Tab

            Logger.Debug("[添加类别] 执行终了");
        }
Ejemplo n.º 4
0
        private void StorageBox_Load(object sender, EventArgs e)
        {
            Logger.Debug("[收纳箱界面加载]执行开始");
            GetJsonPath(JsonFileName);

            // 读取json数据存入tpnList里
            TabPageAll tabPageAll = new TabPageAll();

            try
            {
                TabPageAll obj = JsonAccess.ReadJson_TabNames(JsonPath);

                if (obj != null)
                {
                    foreach (TabPageNames item in obj.TabPageNames)
                    {
                        TabPageNames tpn1 = new TabPageNames();
                        tpn1.Name = item.Name;
                        tabPageAll.TabPageNames.Add(tpn1);
                    }
                }
            }
            catch (Exception e1)
            {
                Logger.Error(e1.ToString());
            }

            if (tabPageAll == null || tabPageAll.TabPageNames.Count == 0)
            {
                return;
            }

            foreach (TabPageNames item in tabPageAll.TabPageNames)
            {
                Logger.Debug("开始添加Tab:" + item.Name.Remove(0, 3));
                tabC_ctx.TabPages.Add(item.Name.Remove(0, 3));
            }
            Logger.Debug("[收纳箱界面加载]执行结束");
        }