private void butAdd_Click(object sender, EventArgs e) { Instrument ins = LqtUtil.GetComboBoxValue <Instrument>(comInstrument); if (ins != null) { MasterProduct pro = LqtUtil.GetComboBoxValue <MasterProduct>(comProduct); if (pro != null) { if (!_test.IsExsistProductUsage(ins.Id, pro.Id)) { ProductUsage pu = new ProductUsage(); pu.Test = _test; pu.Instrument = ins; pu.Product = pro; pu.Rate = 1; _test.ProductUsages.Add(pu); BindProductUsage(); if (OnDataUsageEdit != null) { OnDataUsageEdit(this, new EventArgs()); } } } } }
private void butSave_Click(object sender, EventArgs e) { int count = 0; int error = 0; try { foreach (ImportProUsageData rd in _rdata) { if (!rd.IsExist) { ProductUsage pu = new ProductUsage(); pu.Instrument = rd.Instrument; pu.Product = rd.Product; pu.Rate = rd.Rate; if (rd.IsForControl || rd.UseForBoth) { ProductUsage puC = new ProductUsage(); puC.Instrument = rd.Instrument; puC.Product = rd.Product; puC.Rate = rd.Rate; puC.IsForControl = true; rd.Test.ProductUsages.Add(puC); count++; if (rd.UseForBoth) { pu.IsForControl = false; rd.Test.ProductUsages.Add(pu); count++; } } else { pu.IsForControl = false; rd.Test.ProductUsages.Add(pu); count++; } DataRepository.SaveOrUpdateTest(rd.Test); } else { error++; } } MessageBox.Show(count + "Product Usages are imported and saved successfully." + Environment.NewLine + error + " Products Failed.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch { MessageBox.Show("Error: Unable to imported and saved Product Usage data.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { DataRepository.CloseSession(); } }
private void SaveProductUsage(ProductUsage ProductUsage, SqlTransaction tr) { string sql = "INSERT INTO ProductUsage(ProductId,TestId,Rate) VALUES (@ProductId, @TestId, @Rate) SELECT @@identity"; using (SqlCommand cm = new SqlCommand(sql, DefaultConnection, tr)) { SetProductUsage(cm, ProductUsage); ProductUsage.Id = int.Parse(cm.ExecuteScalar().ToString()); } }
private void FetchProductUsage(SqlDataReader dr, Test test) { while (dr.Read()) { ProductUsage p = new ProductUsage() { Id = DatabaseHelper.GetInt32("Id", dr), TestId = DatabaseHelper.GetInt32("TestId", dr), ProductId = DatabaseHelper.GetInt32("ProductId", dr), Rate = DatabaseHelper.GetMoney("Rate", dr), ProductName = DatabaseHelper.GetString("ProductName", dr), BasicUnit = DatabaseHelper.GetString("BasicUnit", dr), PackSize = DatabaseHelper.GetInt32("PackSize", dr) }; test.ProductUsages.Add(p); } }
private void SetProductUsage(SqlCommand cm, ProductUsage ProductUsage) { DatabaseHelper.InsertInt32Param("@TestId", cm, ProductUsage.TestId); DatabaseHelper.InsertInt32Param("@ProductId", cm, ProductUsage.ProductId); DatabaseHelper.InsertMoneyParam("@Rate", cm, ProductUsage.Rate); }