在WPF中将应用程序数据写入文件的最佳方法

时间:2018-02-11 18:45:36

标签: c# wpf

我正在使用 Caliburn.Micro MVVM模式

我正在编写一个包含2个DataGrids的应用程序,其中一个包含BindableCollection RepairOrder,另一个包含BindableCollection WriteOff

BindableCollection_WriteOffBindableCollection_RepairOrder的财产。 (见下面的代码)。

我需要找到一种方法来编写所有RepairOrder,包括与每个RO关联的WriteOff。除RepairOrder班级持有WriteOff班级外,WriteOff班级无法将WriteOffRepairOrder联系起来。

修理订单类:

public class RepairOrder
{
    public string Schedule { get; set; }
    public string ControlNumber { get; set; }
    public int Age { get; set; }
    public double Value { get; set; }
    public string Note { get; set; }
    public double OrgValue { get; set; }

    private List<WriteOff> _myWriteOffs;

    public List<WriteOff> GetMyWriteOffs()
    {

        return _myWriteOffs;
    }

    public void AddMyWriteOff(WriteOff value)
    { _myWriteOffs.Add(value); }

    public void DeleteMyWriteOff(WriteOff value)
    { _myWriteOffs.Remove(value); }


    public RepairOrder(string CN, string SC, double VL)
    {
        ControlNumber = CN;
        Schedule = SC;
        Value = Math.Round(VL, 2);
        Note = null;
        _myWriteOffs = new List<WriteOff>();
    }

    public RepairOrder()
    {
        _myWriteOffs = new List<WriteOff>();
    }

    public static RepairOrder FromCSV(string CSVLine, string Sched)
    {
        string[] values = CSVLine.Split(',');
        RepairOrder rep = new RepairOrder();
        rep.ControlNumber = values[2];
        rep.Value = Math.Round(double.Parse(values[5]),2);
        rep.Age = int.Parse(values[4]);
        rep.Schedule = Sched;
        return rep;
    }         
}

注销课程:

public class WriteOff
{
    private string _store;
    public string Account { get; set; }
    public string Description { get; set; }
    public double WriteOffAmount { get; set; }
    public string Schedule { get; set; }
    public string Store
    {
        get {
            if (String.IsNullOrEmpty(_store)) return "";
            string temp = _store.Substring(0, 3);
            return temp;
        }
        set { _store = value; }
    }
    public string Note { get; set; }

    public WriteOff(string Acct, string Desc, double Amount, string _store)
    {
        Account = Acct;
        Description = Desc;
        WriteOffAmount = Amount;
        Store = _store;
    }

    public string GetWOAccount() {
        string SchedAccountNumber = "";
        //{ "Navistar", "Cummins", "Misc", "Kenworth", "Mack/Volvo" }


        switch (Account)
        {
            case "Navistar":
                SchedAccountNumber = "222000";
                break;
            case "Cummins":
                SchedAccountNumber = "223000";
                break;
            case "Misc":
                SchedAccountNumber = "224500";
                break;
            default:
                SchedAccountNumber = "";
                break;
        }

        return SchedAccountNumber;
    }
}

0 个答案:

没有答案