コード例 #1
0
        //1.可以往库存里面添加吉他
        //2.按照一定条件来查找吉他

        //个人觉得,主要的文件读写操作都在里面
        //主要需要调用的就是IO类
        public static int FindPrice(List <Guitar> readGuitar)
        {
            double[] priceArray = new double[readGuitar.Count];
            int      i          = 0;

            for (i = 0; i < readGuitar.Count; i++)
            {
                Guitar gx = new Guitar();
                gx = readGuitar.ElementAt(i);
                priceArray.SetValue(System.Convert.ToDouble(gx.Price), i);
            }

            int    positionMax = 0;
            double priceMax    = priceArray[0];
            int    j           = 0;

            while (j != readGuitar.Count)
            {
                if (priceArray[j] > priceMax)
                {
                    positionMax = j;
                    priceMax    = priceArray[j];
                }
                j++;
            }
            return(positionMax);
        }
コード例 #2
0
        private void button_FindPrice_Click(object sender, EventArgs e)
        {
            int    positionMax = StockGuitar.FindPrice(readGuitar);
            Guitar gx          = readGuitar.ElementAt(positionMax);
            string output      = "吉他:\n---------------------\n" + "序列号:" + gx.SerialNumber + ",\n价格:" + gx.Price + ",\n制作人:" + gx.Builder + ",\n模型:" + gx.Model + ",\n型号:" + gx.Type + ",\n前木:" + gx.BackWood + ",\n后木" + gx.TopWood + "\n-----------------------\n是最高价格的吉他。";

            Console.WriteLine(output);
            MessageBox.Show(output);
        }
コード例 #3
0
        private void button_UpLoad_Click(object sender, EventArgs e)
        {
            Guitar rand_guitar = new Guitar(textBox_SerialNumber.Text.ToString(), textBox_Price.Text.ToString(), textBox_Builder.Text.ToString(), textBox_Model.Text.ToString(), textBox_Type.Text.ToString(), textBox_BackWood.Text.ToString(), textBox_TopWood.Text.ToString());

            listGuitars.Add(rand_guitar);
            //使用bindingSource添加数据
            //https://blog.csdn.net/magieclarence/article/details/41863511
            //BindingSource _bs1 = new BindingSource();
            //_bs1.AddingNew += new AddingNewEventHandler(_bs1_AddingNew);
        }
コード例 #4
0
        public Form_Main()
        {
            InitializeComponent();
            CreateFileName();
            textBox_Path.Text        = FileName;
            button_SaveAsCSV.Enabled = false;
            //随机一个CVS文件名
            Guitar g1 = new Guitar("900001", "12.02", "aaa", "bbb", "ccc", "ddd", "eee");

            textBox_Builder.Text      = g1.Builder;
            textBox_BackWood.Text     = g1.BackWood;
            textBox_Model.Text        = g1.Model;
            textBox_TopWood.Text      = g1.TopWood;
            textBox_Price.Text        = g1.Price;
            textBox_SerialNumber.Text = g1.SerialNumber;
            textBox_Type.Text         = g1.Type;

            button_FindPrice.Enabled = false;
        }
コード例 #5
0
        //https://blog.csdn.net/duyusean/article/details/73381502
        public static List <Guitar> ReadCSV(string m_Path)
        {
            Form_Main     fm         = new Form_Main();
            List <Guitar> readGuitar = new List <Guitar>();
            string        line       = string.Empty;

            fm.openFileDialog1.ShowDialog();
            using (StreamReader sr = new StreamReader(fm.openFileDialog1.FileName))
            {
                fm.label_ReadCSV.Text = fm.openFileDialog1.FileName.ToString();
                string wasteLine = sr.ReadLine();
                Console.WriteLine(wasteLine);
                while ((line = sr.ReadLine()) != null)
                {
                    string[] sArray = line.Split(',');// 一定是单引
                    int      length = sArray.Length;
                    Guitar   gx     = new Guitar(sArray[0], sArray[1], sArray[2], sArray[3], sArray[4], sArray[5], sArray[6]);
                    readGuitar.Add(gx);
                }
                sr.Close();
                Console.WriteLine("已成功读取文件");
            }
            return(readGuitar);
        }