internal void save(InvoiceItemObj obj) { string txtQuery = string.Empty; if (obj.id == 0) { // insert txtQuery = string.Format("INSERT INTO {0} (invoice_id,number,price_per_unit,discount,quantity,unit,unit_xml,item_total,item_name,item_code,item_code_inter) VALUES ", this.tableName); string values = string.Format("(@invoice_id,@number,@price_per_unit,@discount,@quantity,@unit,@unit_xml,@item_total,@item_name,@item_code,@item_code_inter)"); txtQuery = txtQuery + values; } else { //update txtQuery = string.Format("UPDATE {0} SET ", this.tableName); string values = string.Format("invoice_id=@invoice_id,number=@number,price_per_unit=@price_per_unit,discount=@discount" + ",quantity=@quantity,unit=@unit,unit_xml=@unit_xml,item_total=@item_total,item_name=@item_name,item_code=@item_code,item_code_inter=@item_code_inter "); string condition = string.Format("WHERE id=@id"); txtQuery = txtQuery + values + condition; } using (SQLiteConnection c = new SQLiteConnection(sqlite.ConnectionString)) { c.Open(); using (SQLiteCommand cmd = new SQLiteCommand(txtQuery, c)) { cmd.Parameters.AddWithValue("@invoice_id", obj.invoiceId); cmd.Parameters.AddWithValue("@number", obj.number); cmd.Parameters.AddWithValue("@price_per_unit", obj.pricePerUnit); cmd.Parameters.AddWithValue("@discount", obj.discountTotal); cmd.Parameters.AddWithValue("@quantity", obj.quantity); cmd.Parameters.AddWithValue("@unit", obj.unit); cmd.Parameters.AddWithValue("@unit_xml", obj.unitXml); cmd.Parameters.AddWithValue("@item_total", obj.itemTotal); cmd.Parameters.AddWithValue("@item_name", obj.itemName); cmd.Parameters.AddWithValue("@item_code", obj.itemCode); cmd.Parameters.AddWithValue("@item_code_inter", obj.itemCodeInter); if (obj.id != 0) { cmd.Parameters.AddWithValue("@id", obj.id); } try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } } } }
private void OnHyperlinkClick(object sender, RoutedEventArgs e) { Hyperlink button = sender as Hyperlink; InvoiceItemObj itemObj = button.DataContext as InvoiceItemObj; InvoiceItem config = new InvoiceItem(); List <InvoiceItemObj> items = listView.Items.Cast <InvoiceItemObj>().ToList(); config.itemObj = itemObj; bool result = config.ShowDialog().Value; if (result) { var item = items.Find(x => (x.number == config.itemObj.number)); item = config.itemObj; } setItemsSource(items); calculate(); this.Show(); }
private bool saveData() { try { validateData(); if (itemObj == null) { itemObj = new InvoiceItemObj(); } itemObj.itemName = itemNameCbb.Text; itemObj.discount = Convert.ToDouble(discountTotalTb.Text); itemObj.itemCode = itemCodeTb.Text; itemObj.itemCodeInter = itemCodeInterTb.Text; itemObj.pricePerUnit = Convert.ToDouble(pricePerUnitTb.Text); itemObj.pricePerUnitText = itemObj.pricePerUnit.ToString(); itemObj.discount = Convert.ToDouble(discountTb.Text); itemObj.quantity = Convert.ToInt32(quantityTb.Text); itemObj.quantityText = itemObj.quantity.ToString(); itemObj.discountTotal = Convert.ToDouble(discountTotalTb.Text); itemObj.itemTotal = Convert.ToDouble(itemTotalTb.Text); itemObj.itemTotalText = itemObj.itemTotal.ToString().Replace(",", ""); if (itemObj.discount == 0.0) { itemObj.discountText = itemObj.discountTotal.ToString() + " บาท"; } else { itemObj.discountText = itemObj.discount + " % " + itemObj.discountTotal.ToString() + " บาท"; } if (is_service.IsChecked.Value) { itemObj.is_service = true; itemObj.unit = ""; itemObj.unitXml = ""; } else { itemObj.is_service = false; CodeList codelist = (CodeList)unitCbb.SelectedItem; if (codelist == null) { if (unitCbb.Text == "") { itemObj.unitXml = ""; } else { itemObj.unitXml = "ZZ"; } itemObj.unit = unitCbb.Text; } else { itemObj.unit = codelist.description; itemObj.unitXml = codelist.code; } } this.DialogResult = true; return(true); } catch (Exception ex) { new AlertBox(ex.Message).ShowDialog(); return(false); } }