示例#1
0
        private bool InitData(String datapath)
        {
            rawdata = new List <RawDataItem>();

            try
            {
                StreamReader sr = new StreamReader(datapath);
                String       line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] items = line.Split(devider);
                    var      item  = new RawDataItem()
                    {
                        Type = items[0].Trim(),
                        From = items[1].Trim(),
                        To   = Convert.ToDouble(items[2].Trim(), CultureInfo.InvariantCulture),
                        Cost = Convert.ToDouble(items[3].Trim(), CultureInfo.InvariantCulture),
                    };
                    rawdata.Add(item);
                }
                sr.Close();
                BuildSummary();
            } catch (IOException ex)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        private bool InitData(string datapath)
        {
            rawData = new List <RawDataItem>();

            try
            {
                StreamReader sr = new StreamReader(datapath, Encoding.Default);
                string       line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] items = line.Split(devider);

                    RawDataItem item = new RawDataItem();
                    item.Name     = items[0];
                    item.Price    = Convert.ToSingle(items[1]);
                    item.Count    = Convert.ToInt32(items[2]);
                    item.Market   = items[3];
                    item.SumPrice = item.Price * item.Count;
                    rawData.Add(item);
                }

                sr.Close();
                BuildAverage();
            } catch (IOException ex) { return(false); }

            return(true);
        }
示例#3
0
        private bool InitData(String datapath)
        {
            rawdata = new List <RawDataItem>();

            try
            {
                StreamReader sr = new StreamReader(datapath, Encoding.UTF8);
                String       line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] items = line.Split(devider);
                    var      item  = new RawDataItem()
                    {
                        Name     = items[0].Trim(),
                        Group    = items[1].Trim(),
                        Price    = Convert.ToSingle(items[2].Trim()),
                        Discount = Convert.ToSingle(items[3].Trim())
                    };
                    rawdata.Add(item);
                }

                sr.Close();
                BuildSummary();
            }
            catch (IOException ex)
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        private bool InitData(String datapath)
        {
            rawdata = new List <RawDataItem>();

            try
            {
                StreamReader sr = new StreamReader(datapath, System.Text.Encoding.UTF8);
                String       line;

                while ((line = sr.ReadLine()) != null)
                {
                    string[] items = line.Split(devider);
                    //MessageBox.Show(items[0]);
                    var item = new RawDataItem()
                    {
                        Name  = items[0].Trim(),
                        fLine = items[1].Trim(),
                        date  = items[2].Trim(),
                        id    = Convert.ToInt32(items[3].Trim(), CultureInfo.InvariantCulture),
                    };
                    rawdata.Add(item);
                }
                sr.Close();
                BuildSummary();
            } catch (IOException ex)
            {
                return(false);
            }
            return(true);
        }
示例#5
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataStorage data;

            try
            {
                data = DataStorage.DataCreator(openFileDialog1.FileName);
                RawDataItem nn = new RawDataItem();
                nn.Name  = textBox1.Text;
                nn.fLine = textBox5.Text;
                nn.id    = Convert.ToInt32(textBox2.Text);
                nn.date  = textBox3.Text;
                if (textBox4.Text == "УДАЛИТЬ" || textBox4.Text == "REMOVE")
                {
                    StreamReader       sr = new StreamReader(openFileDialog1.FileName, System.Text.Encoding.UTF8);
                    String             line;
                    List <RawDataItem> rawdata;
                    rawdata = new List <RawDataItem>();
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] items = line.Split('*');
                        var      item  = new RawDataItem()
                        {
                            Name  = items[0].Trim(),
                            fLine = items[1].Trim(),
                            date  = items[2].Trim(),
                            id    = Convert.ToInt32(items[3].Trim()),
                        };
                        rawdata.Add(item);
                    }
                    sr.Close();

                    using (StreamWriter sw = new StreamWriter(openFileDialog1.FileName, false, System.Text.Encoding.UTF8))
                    {
                        foreach (var item in rawdata)
                        {
                            if (item.date != nn.date || item.Name != nn.Name || item.id != nn.id || item.fLine != nn.fLine)
                            {
                                sw.WriteLine(item.Name + " * " + item.fLine + " * " + item.date + " * " + Convert.ToString(item.id));
                            }
                        }
                    }
                    ShowData(openFileDialog1.FileName);
                }
                else if (textBox4.Text == "ДОБАВИТЬ" || textBox4.Text == "ADD")
                {
                    using (StreamWriter sw = new StreamWriter(openFileDialog1.FileName, true, System.Text.Encoding.UTF8))
                    {
                        string s1 = nn.Name + " * " + nn.fLine + " * " + nn.date + " * " + Convert.ToString(nn.id);
                        sw.WriteLine(s1);
                    }
                    ShowData(openFileDialog1.FileName);
                }
                else
                {
                    MessageBox.Show("Вы неправильно ввели действие");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Проверьте корректность данных");
            }
        }