示例#1
0
        private void InputCompositionsDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            var row        = InputDGV.Rows[e.RowIndex];
            var type       = row.Cells["Type"].Value?.ToString();
            var surname    = row.Cells["inputDGV_Surname"].Value?.ToString();
            var progsCount = Convert.ToInt32(row.Cells["inputDGV_ProgsCount"].Value);
            var langCount  = Convert.ToInt32(row.Cells["inputDGV_LangCount"].Value);

            if (progsCount >= 0 && langCount >= 0)
            {
                if (type == "Programmer")
                {
                    var tv = new Programmer(surname, progsCount, langCount);
                    row.Cells["InputDGV_SuccessProgs"].Value = "";
                    row.Cells["inputDGV_Q"].Value            = tv.Q();
                }
                else
                {
                    var successProgs = Convert.ToInt32(row.Cells["inputDGV_SuccessProgs"].Value);
                    if (successProgs >= 0)
                    {
                        var tv = new CustomProgrammer(surname, progsCount, langCount, successProgs);
                        row.Cells["inputDGV_Q"].Value = tv.Q();
                    }
                }
            }
        }
示例#2
0
        public static List <Programmer> ReadFromFile(string path)
        {
            List <Programmer> prList = new List <Programmer>();

            string[] fileLines = File.ReadAllLines(path, Encoding.Default);

            foreach (string line in fileLines)
            {
                string[]   parts = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                Programmer pr    = null;
                string     surname;
                int        progCount, langCount;
                switch (parts[0])
                {
                case "Programmer":
                    surname   = parts[1];
                    progCount = int.Parse(parts[2]);
                    langCount = int.Parse(parts[3]);
                    pr        = new Programmer(surname, progCount, langCount);
                    break;

                case "CustomProgrammer":
                    surname   = parts[1];
                    progCount = int.Parse(parts[2]);
                    langCount = int.Parse(parts[3]);
                    int successProgs = int.Parse(parts[4]);
                    pr = new CustomProgrammer(surname, progCount, langCount, successProgs);
                    break;
                }
                if (pr != null)
                {
                    prList.Add(pr);
                }
            }
            return(prList);
        }