private void butAddI_Click_1(object sender, EventArgs e) { Instrument ins = LqtUtil.GetComboBoxValue <Instrument>(comInstrumentI); if (ins != null) { MasterProduct pro = LqtUtil.GetComboBoxValue <MasterProduct>(comProductI); if (pro != null) { //if (! _consum.IsExsistProductUsage(ins.Id, pro.Id)) // { if (comPeriodI.SelectedValue != null) { if (!_consum.IsExsistUsageRatePerInst(ins.Id, pro.Id)) { ConsumableUsage cu = new ConsumableUsage(); cu.Period = comPeriodI.Text; cu.PerInstrument = true; cu.Product = pro; cu.Instrument = ins; cu.ProductUsageRate = 1; cu.MasterConsumable = _consum; _consum.ConsumableUsages.Add(cu); BindProductUsageI(); if (OnDataUsageEdit != null) { OnDataUsageEdit(this, new EventArgs()); } } } } } }
private IList <ImportProUsageData> GetDataRow(DataSet ds) { string testName; string insName; string proName; string period; int noOfTest; decimal rate; string tName = ""; string iName = ""; bool isForTest = false; bool isForPeriod = false; bool isForInstrument = false; MasterConsumable cons = null; Test test = null; Instrument instrument = null; bool isnew = false; int rowno = 0; bool haserror; IList <ImportProUsageData> rdlist = new List <ImportProUsageData>(); List <string> con = new List <string>(); foreach (DataRow dr in ds.Tables[0].Rows) { rowno++; haserror = false; testName = Convert.ToString(dr[0]).Trim(); //region name insName = Convert.ToString(dr[1]).Trim(); proName = Convert.ToString(dr[2]).Trim(); period = Convert.ToString(dr[3]).Trim(); try { noOfTest = int.Parse(Convert.ToString(dr[4])); } catch { noOfTest = 0; } try { rate = decimal.Parse(Convert.ToString(dr[5])); } catch { rate = 1; } try { isForTest = Convert.ToBoolean(int.Parse(Convert.ToString(dr[6]))); } catch { isForTest = false; } try { isForPeriod = Convert.ToBoolean(int.Parse(Convert.ToString(dr[7]))); } catch { isForPeriod = false; } try { isForInstrument = Convert.ToBoolean(int.Parse(Convert.ToString(dr[8]))); } catch { isForInstrument = false; } ImportProUsageData rd = new ImportProUsageData(testName, insName, proName, period, noOfTest, rate, isForTest, isForPeriod, isForInstrument, rowno); if (!string.IsNullOrEmpty(Convert.ToString(dr[0]))) { SaveConsumable(Convert.ToString(dr[0])); } if (tName != testName) { if (!string.IsNullOrEmpty(testName)) { test = DataRepository.GetTestByName(testName); } else { test = null; } tName = testName; } if (test != null) { // rd.Test = test; cons = DataRepository.GetConsumableByName(testName); rd.Cons = cons; if (iName != insName) { if (!String.IsNullOrEmpty(insName)) { instrument = DataRepository.GetInstrumentByName(insName); } else { instrument = null; } iName = insName; } if (instrument != null) { rd.Instrument = instrument; if (!String.IsNullOrEmpty(proName) && !String.IsNullOrEmpty(rd.Period)) { rd.Product = DataRepository.GetProductByName(proName); if (rd.Product == null) { haserror = true; } if (!isnew) { if (cons.IsExsistUsageRatePerInst(instrument.Id, rd.Product.Id) && rd.IsForInstrument == true) { rd.IsExist = true; } } } else { haserror = true; } } // else // haserror = true; if (rd.IsForPeriod == true) { if (!String.IsNullOrEmpty(proName) && !String.IsNullOrEmpty(rd.Period)) { rd.Product = DataRepository.GetProductByName(proName); if (rd.Product == null) { haserror = true; } if (!isnew) { if (cons.IsExsistUsageRatePerPeriod(rd.Product.Id)) { rd.IsExist = true; } } } else { haserror = true; } } if (rd.IsForTest == true) { if (!String.IsNullOrEmpty(proName) && rd.NoOfTest > 0) { rd.Product = DataRepository.GetProductByName(proName); if (rd.Product == null) { haserror = true; } if (!isnew) { if (cons.IsExsistUsageRatePerPeriod(rd.Product.Id)) { rd.IsExist = true; } } } else { haserror = true; } } } else { haserror = true; } rd.HasError = haserror; rdlist.Add(rd); isnew = false; } return(rdlist); }