summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-08-08 06:35:02 +0200
committerSebastian Reichel <sre@ring0.de>2012-08-08 06:35:02 +0200
commitb11374fbf4a9e8900c1471dc1e8350a07d8a4a68 (patch)
tree4726b527cdee593cdeb9c5af1e7eff40944a50c0
parent9baee483352ad3a47e748eb33e6efaca81df13c7 (diff)
downloadserial-barcode-scanner-b11374fbf4a9e8900c1471dc1e8350a07d8a4a68.tar.bz2
implement & enable new stock dialog
-rw-r--r--db.vala36
-rw-r--r--ui.vala14
-rw-r--r--user-interface.ui133
3 files changed, 120 insertions, 63 deletions
diff --git a/db.vala b/db.vala
index 8adf81d..10687f4 100644
--- a/db.vala
+++ b/db.vala
@@ -13,6 +13,14 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+public struct StockEntry {
+ public string id;
+ public string name;
+ public int amount;
+ public string memberprice;
+ public string guestprice;
+}
+
public class Database {
private Sqlite.Database db;
private Sqlite.Statement product_stmt;
@@ -25,6 +33,7 @@ public class Database {
private Sqlite.Statement stock_stmt1;
private Sqlite.Statement stock_stmt2;
private Sqlite.Statement price_stmt;
+ private Sqlite.Statement stock_status_stmt;
int32 user = 0;
bool logged_in = false;
private static string product_query = "SELECT name FROM products WHERE id = ?";
@@ -37,6 +46,7 @@ public class Database {
private static string stock_query1 = "INSERT INTO restock ('user', 'product', 'amount', 'timestamp') VALUES (?, ?, ?, ?)";
private static string stock_query2 = "UPDATE products SET amount = amount + ? WHERE id = ?";
private static string price_query = "SELECT memberprice, guestprice FROM prices WHERE product = ? AND valid_from <= ? ORDER BY valid_from DESC LIMIT 1";
+ private static string stock_status_query = "SELECT id, name, amount, memberprice, guestprice FROM products, prices WHERE products.id = prices.product AND products.amount > 0 AND prices.valid_from = (SELECT valid_from FROM prices WHERE product = products.id ORDER BY valid_from DESC LIMIT 1)";
public Database(string file) {
int rc;
@@ -96,6 +106,10 @@ public class Database {
error("could not prepare price statement!");
}
+ rc = this.db.prepare_v2(stock_status_query, -1, out stock_status_stmt);
+ if(rc != Sqlite.OK) {
+ error("could not prepare stock status statement!");
+ }
}
public bool login(int32 id) {
@@ -120,6 +134,28 @@ public class Database {
return result;
}
+ public Gee.List<StockEntry?> get_stock() {
+ var result = new Gee.ArrayList<StockEntry?>();
+ this.stock_status_stmt.reset();
+
+ while(this.stock_status_stmt.step() == Sqlite.ROW) {
+ StockEntry entry = {
+ this.stock_status_stmt.column_text(0),
+ this.stock_status_stmt.column_text(1),
+ this.stock_status_stmt.column_int(2),
+ null,
+ null
+ };
+
+ entry.memberprice = "%d.%02d€".printf(this.stock_status_stmt.column_int(3) / 100, this.stock_status_stmt.column_int(3) % 100);
+ entry.guestprice = "%d.%02d€".printf(this.stock_status_stmt.column_int(4) / 100, this.stock_status_stmt.column_int(4) % 100);
+
+ result.add(entry);
+ }
+
+ return result;
+ }
+
public bool buy(uint64 article) {
if(is_logged_in()) {
int rc = 0;
diff --git a/ui.vala b/ui.vala
index 843198b..a5d37a4 100644
--- a/ui.vala
+++ b/ui.vala
@@ -21,7 +21,6 @@ public void init_ui() {
public void init_main_window() {
var window = builder.get_object("main") as Gtk.Window;
- /* TODO */
window.destroy.connect(() => {
Gtk.main_quit();
});
@@ -76,6 +75,19 @@ public void show_main_window() {
(builder.get_object("main") as Gtk.Window).show();
}
+public void show_stock_dialog() {
+ var liststore = builder.get_object("stock-store") as Gtk.ListStore;
+ liststore.clear();
+
+ Gtk.TreeIter iter;
+ foreach(var item in db.get_stock()) {
+ liststore.append(out iter);
+ liststore.set(iter, 0, item.id, 1, item.name, 2, item.amount, 3, item.memberprice, 4, item.guestprice, -1);
+ }
+
+ (builder.get_object("stock-dialog") as Gtk.Window).show();
+}
+
[PrintfFormat]
public void write_to_log(string format, ...) {
var arguments = va_list();
diff --git a/user-interface.ui b/user-interface.ui
index be36742..a2fafe0 100644
--- a/user-interface.ui
+++ b/user-interface.ui
@@ -188,10 +188,10 @@ Lennart Weller &lt;lhw@ring0.de&gt;</property>
<property name="label" translatable="yes">Stock &amp; Price Information</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="image">image4</property>
<property name="use_stock">False</property>
+ <signal name="activate" handler="show_stock_dialog" swapped="no"/>
</object>
</child>
<child>
@@ -599,11 +599,30 @@ Lennart Weller &lt;lhw@ring0.de&gt;</property>
<action-widget response="0">button-restock-add</action-widget>
</action-widgets>
</object>
+ <object class="GtkListStore" id="stock-store">
+ <columns>
+ <!-- column-name id -->
+ <column type="gchararray"/>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ <!-- column-name amount -->
+ <column type="gint"/>
+ <!-- column-name memberprice -->
+ <column type="gchararray"/>
+ <!-- column-name guestprice -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkDialog" id="stock-dialog">
+ <property name="width_request">400</property>
+ <property name="height_request">500</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">stock</property>
<property name="type_hint">dialog</property>
+ <signal name="close" handler="gtk_widget_hide" swapped="no"/>
+ <signal name="delete-event" handler="gtk_widget_hide_on_delete" swapped="no"/>
+ <signal name="response" handler="gtk_widget_hide" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox4">
<property name="can_focus">False</property>
@@ -643,77 +662,67 @@ Lennart Weller &lt;lhw@ring0.de&gt;</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
- <object class="GtkViewport" id="viewport1">
+ <object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can_focus">True</property>
+ <property name="model">stock-store</property>
+ <property name="search_column">1</property>
+ <property name="enable_grid_lines">vertical</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="treeview-selection"/>
+ </child>
<child>
- <object class="GtkGrid" id="grid4">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <property name="title" translatable="yes">ID</property>
<child>
- <object class="GtkLabel" id="label7">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">EAN</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
</child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+ <property name="title" translatable="yes">Name</property>
<child>
- <object class="GtkLabel" id="label8">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Name</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
+ <object class="GtkCellRendererText" id="cellrenderertext2"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
</child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn3">
+ <property name="title" translatable="yes">Amount</property>
<child>
- <object class="GtkLabel" id="label9">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Amount</property>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
+ <object class="GtkCellRendererText" id="cellrenderertext3"/>
+ <attributes>
+ <attribute name="text">2</attribute>
+ </attributes>
</child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn4">
+ <property name="title" translatable="yes">Member Price</property>
<child>
- <object class="GtkLabel" id="label10">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Member Price</property>
- </object>
- <packing>
- <property name="left_attach">3</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
+ <object class="GtkCellRendererText" id="cellrenderertext4"/>
+ <attributes>
+ <attribute name="text">3</attribute>
+ </attributes>
</child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn5">
+ <property name="title" translatable="yes">Guest Price</property>
<child>
- <object class="GtkLabel" id="label11">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Guest Price</property>
- </object>
- <packing>
- <property name="left_attach">4</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
+ <object class="GtkCellRendererText" id="cellrenderertext5"/>
+ <attributes>
+ <attribute name="text">4</attribute>
+ </attributes>
</child>
</object>
</child>
@@ -721,7 +730,7 @@ Lennart Weller &lt;lhw@ring0.de&gt;</property>
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>