Пример #1
0
        /// <summary>
        /// 根据指定的分割字符c将源字符串src分割,并用于初始化实例
        /// </summary>
        /// <param name="src"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public static bool Load(string src, char c, out IEBF obj)
        {
            obj = new IEBF();

            if (src != null &&
                !string.IsNullOrWhiteSpace(src))
            {
                string[] strs = src.Split(c);

                if (strs.Length >= 5)
                {
                    obj.Date    = strs[0];
                    obj.Account = strs[1];
                    obj.InOut   = strs[2];
                    obj.Count   = Double.Parse(strs[3]);
                    obj.Comment = strs[4];

                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// 从保存的操作信息文件中解析出收支信息
        /// </summary>
        private void getInoutDetailsFromMessage()
        {
            if (!string.IsNullOrWhiteSpace(messages))
            {
                string[] msgs = messages.Replace("\r\n", "\r").Split("\r".ToArray(), StringSplitOptions.RemoveEmptyEntries);

                double totalIn  = 0.0;
                double totalOut = 0.0;
                double salaryIn = 0.0;
                double profitIn = 0.0;
                double otherIn  = 0.0;

                foreach (string _s in msgs)
                {
                    string s = _s;

                    if (string.IsNullOrWhiteSpace(s) != true)
                    {
                        while (s.Contains("  "))
                        {
                            s = s.Replace("  ", " ");
                        }

                        if (s.Contains("Error:") ||
                            s.Contains("Err"))
                        {
                            continue;
                        }

                        if (s.Contains("收入") ||
                            s.Contains("支出"))
                        {
                            //string date = s.Substring(0, s.IndexOf(':'));
                            //string inOut = s.Contains("支出") ? "支出" : (s.Contains("工资收入") ? "工资收入" : (s.Contains("收益收入") ? "收益收入" : "其他收入"));
                            //int startOffset = inOut.Equals("支出") ? 2 : 4;
                            //string count = s.Substring(s.IndexOf(inOut) + startOffset,
                            //    s.IndexOf("元") - s.IndexOf(inOut) - startOffset).Trim();
                            //string comment = s.Substring(s.IndexOf("详情:") + 3, s.Length - s.IndexOf("详情:") - 3);

                            /*
                             * 修改参数获取方式,原有方式过于简陋,无法应付用户不合法的输入信息。
                             */
                            try
                            {
                                string tmp = s;

                                string date = tmp.Substring(0, tmp.IndexOf(' ') - 1);
                                tmp = tmp.Substring(tmp.IndexOf(' ') + 1);

                                string account = tmp.Substring(0, tmp.IndexOf(' '));
                                tmp = tmp.Substring(tmp.IndexOf(' ') + 1);

                                string inOut = tmp.Substring(0, tmp.IndexOf(' '));
                                tmp = tmp.Substring(tmp.IndexOf(' ') + 1);

                                string count = tmp.Substring(0, tmp.IndexOf(' '));
                                tmp = tmp.Substring(tmp.IndexOf(' ') + 1);

                                string comment = tmp.Substring(tmp.IndexOf(':') + 1);

                                IEBF i = new IEBF();

                                i.Date    = date;
                                i.Account = account;
                                i.InOut   = inOut;
                                i.Count   = Double.Parse(count);
                                i.Comment = comment;

                                /*
                                 * 信用卡的收支由于最终会体现为非信用卡账户的收支,所以信用卡的收支不计算在内
                                 */
                                if (i.Account.Contains("信用卡"))
                                {
                                    continue;
                                }

                                /*
                                 *分类统计求和
                                 *总收入(工资+收益+其他)
                                 *总支出
                                 */
                                if (i.InOut == "工资收入")
                                {
                                    salaryIn += i.Count;
                                }
                                else if (i.InOut == "收益收入")
                                {
                                    profitIn += i.Count;
                                }
                                else if (i.InOut == "其他收入")
                                {
                                    otherIn += i.Count;
                                }
                                else if (i.InOut == "支出")
                                {
                                    totalOut += i.Count;
                                }

                                this.iebfCollection.Add(i);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Exception Occured: " + ex.Message);
                            }
                        }
                    }
                }

                totalIn = salaryIn + profitIn + otherIn;

                this.totalInLb.Content  = totalIn.ToString("F2");
                this.totalOutLb.Content = totalOut.ToString("F2");
                this.salaryInLb.Content = salaryIn.ToString("F2");
                this.profitInLb.Content = profitIn.ToString("F2");
                this.otherInLb.Content  = otherIn.ToString("F2");
            }
        }