private void button1_Click(object sender, EventArgs e) { string path = @"C:\Users\cuong\Desktop\Record\LOG_20170211.csv"; using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new StreamReader(stream)) using (var csv = new CsvReader(reader)) { ConfigureCsvReader(csv); var myClassMap = new MyClassMap(); csv.Configuration.RegisterClassMap(myClassMap); var testProg = csv.GetRecords <MyClass>().Last(i => i.ColA == "TestProg"); if (testProg.ColE == "Pass") { var subProg = csv.GetRecords <MyClass>().Last(i => i.ColA == "SubProg" && i.ColC == "Cmd"); if (subProg.ColF == "Pass") { MessageBox.Show("PASS SubProg"); } else if (testProg.ColE == "Fail") { MessageBox.Show("Fail SubProg"); } } else if (testProg.ColE == "Fail") { MessageBox.Show("Fail TestProg"); } } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <returns></returns> private string StateWorking(string path) { //path = @"C:\Users\cuong\Desktop\Record\LOG_20170211.csv"; string status = ""; using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new StreamReader(stream)) using (var csv = new CsvReader(reader)) { ConfigureCsvReader(csv); var myClassMap = new MyClassMap(); csv.Configuration.RegisterClassMap(myClassMap); var testProg = csv.GetRecords <MyClass>().Last(i => i.ColA == "TestProg"); if (testProg.ColE == "Pass") { var subProg = csv.GetRecords <MyClass>().Last(i => i.ColA == "SubProg" && i.ColC == "Cmd"); if (subProg.ColF == "Pass") { status = "P"; } else if (testProg.ColE == "Fail") { status = "F"; } } else if (testProg.ColE == "Fail") { status = "F"; } } return(status); }
private void btnSaveChanged_Click(object sender, EventArgs e) { if (!CheckTextBoxNullValue.ValidationTextEditNullValue(txtModelName)) { CheckTextBoxNullValue.ValidationTextEditNullValueWidthErrorProvider(dxErrorProvider1, txtModelName, "Nhập vào tên Model!"); } else { List <Model> lists = new List <Model>(); string path = AppDomain.CurrentDomain.BaseDirectory + @"\Data\HondaLookModel.csv"; using (var stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) using (var reader = new StreamReader(stream)) using (var csv = new CsvReader(reader)) { ConfigureCsvReader(csv); var myClassMap = new MyClassMap(); csv.Configuration.RegisterClassMap(myClassMap); var model = new Model() { ModelCode = txtModelCode.Text, ModelName = txtModelName.Text }; lists.Add(model); bool datontai = false; var models = csv.GetRecords <Model>().OrderBy(i => i.ModelCode).ToList(); foreach (var item in models) { if (item.ModelCode == model.ModelCode) { MessageBox.Show("Model đã có rồi!"); datontai = true; break; } } if (datontai == false) { using (TextWriter writer = new StreamWriter(stream)) { foreach (var item in lists) { var csvWriter = new CsvWriter(writer); csvWriter.WriteRecord(item); } MessageBox.Show("Insert success!"); } } } GetModels(); txtModelName.ResetText(); txtModelName.Focus(); } }
/// <summary> /// /// </summary> private void GetModels() { string path = AppDomain.CurrentDomain.BaseDirectory + @"\Data\HondaLookModel.csv"; using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new StreamReader(stream)) using (var csv = new CsvReader(reader)) { ConfigureCsvReader(csv); var myClassMap = new MyClassMap(); csv.Configuration.RegisterClassMap(myClassMap); var models = csv.GetRecords <Model>().OrderBy(i => i.ModelCode); gridControl1.DataSource = models.ToList(); } }