public bool DoCarrier(ref string mess) { var cmd = db.CreateCommand(); cmd.CommandText = "insert into DELIVERY(DL_W_ID,DL_ID,DL_CARRIER_ID) select " + wid + ",count(a.DL_ID)+1," + carid + " from delivery a where a.DL_W_ID=" + wid; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); Set(1, carid); Set(2, "Delivery has been scheduled"); return(false); }
public bool DoCommit(ref string mess) { bool done = false; try { for (int j = 0; j < ol_cnt; j++) { OrderLine a = ols[j]; s_quantity = a.s_quantity - a.ol_quantity; if (s_quantity < 10) { s_quantity += 91; } var cmd = db.CreateCommand(); cmd.Transaction = tr; cmd.CommandText = "update STOCK set S_QUANTITY=" + s_quantity + " where S_I_ID=" + a.oliid + " and S_W_ID=" + a.ol_supply_w_id; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); cmd.CommandText = "insert into ORDER_LINE(OL_O_ID,OL_D_ID,OL_W_ID,OL_NUMBER,OL_I_ID,OL_SUPPLY_W_ID,OL_QUANTITY,OL_AMOUNT)values(" + o_id + "," + did + "," + wid + "," + (j + 1) + "," + a.oliid + "," + a.ol_supply_w_id + "," + a.ol_quantity + "," + a.ol_amount + ")"; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); } mess = "OKAY"; int rbk = util.random(1, 100); if (rbk == 1) { tr.Rollback(); tr = null; done = true; } else { tr.Commit(); Form1.commits++; tr = null; } // Phase 3 display the results Set(130, "OKAY"); done = true; } catch (Exception ex) { Set(130, ex.Message); Form1.RecordResponse(ex, fid, tid); tr.Rollback(); Form1.wconflicts++; } return(done); }
bool DoPayment(ref string mess) { Set(35, c_amount.ToString()); var cmd = db.CreateCommand(); cmd.Transaction = tr; cmd.CommandText = "update DISTRICT set D_YTD=" + (dytd + c_amount) + " where D_W_ID=" + wid + " and D_ID=" + did; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); Set(36, (c_balance + c_amount).ToString("F2")); cmd.CommandText = "update CUSTOMER set C_BALANCE=" + (c_amount + c_balance) + ",C_YTD_PAYMENT=" + (c_amount + c_ytd_payment) + ",C_PAYMENT_CNT=" + (c_payment_cnt + 1) + " where C_W_ID = " + wid + " and C_D_ID = " + cdid + " and C_ID = " + cid; cmd.ExecuteNonQuery(); cmd.CommandText = "update WAREHOUSE set W_YTD=" + (ytd + c_amount) + " where W_ID=" + wid; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); if (c_credit == "BC") { cmd.CommandText = "select C_DATA from CUSTOMER where C_W_ID=" + wid + " and C_D_ID=" + cdid + " and C_ID=" + cid; var s = cmd.ExecuteReader(); if (!s.Read()) { s.Close(); return(true); } cdata = (string)s[0]; s.Close(); cdata = "" + cid + "," + cdid + "," + wid + "," + did + "," + wid + "," + c_amount + ";" + cdata; if (cdata.Length > 500) { cdata = cdata.Substring(0, 500); } cmd.CommandText = "update CUSTOMER set c_data='" + cdata + "' where C_W_ID=" + wid + " and C_D_ID=" + cdid + " and C_ID=" + cid; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); Set(38, cdata.Substring(0, 50)); if (cdata.Length > 50) { Set(39, cdata.Substring(50, 50)); } if (cdata.Length > 100) { Set(40, cdata.Substring(100, 50)); } if (cdata.Length > 150) { Set(41, cdata.Substring(150, 50)); } } return(false); }
bool DoOLCount(ref string mess) { Set(7, ol_cnt); var cmd = db.CreateCommand(); cmd.Transaction = tr; cmd.CommandText = "insert into [ORDER](O_ID,O_D_ID,O_W_ID,O_C_ID,O_ENTRY_D,O_OL_CNT,O_ALL_LOCAL)" + "values(" + o_id + "," + did + "," + wid + "," + cid + ",'" + DateTime.Now.ToString("o") + "'," + ol_cnt + "," + (allhome ? "1" : "0") + ")"; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); cmd.CommandText = "insert into NEW_ORDER(NO_O_ID,NO_D_ID,NO_W_ID)values(" + o_id + "," + did + "," + wid + ")"; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); return(false); }
public bool FetchCarrier(ref string mess) { var cmd = db.CreateCommand(); cmd.CommandText = "select DL_DONE,DK_SKIPPED from DELIVERY where DL_W_ID=" + wid + " and DL_CARRIER_ID=" + carid + " order by DL_ID desc"; Form1.RecordRequest(cmd, fid, tid); var s = cmd.ExecuteReader(); var r = s.Read(); if (r) { Set(3, (int)s[0]); Set(4, (int)s[1]); } s.Close(); return(!r); }
bool Schedule(int did, int carid, SqlTransaction tr) { int oid = 0; int ocid = 0; var cmd = db.CreateCommand(); cmd.Transaction = tr; cmd.CommandText = "select NO_O_ID from NEW_ORDER where NO_W_ID=" + wid + " and NO_D_ID=" + did; Form1.RecordRequest(cmd, fid, tid); var s = cmd.ExecuteReader(); if (!s.Read()) { s.Close(); return(false); } oid = (int)s[0]; s.Close(); cmd.CommandText = "delete NEW_ORDER where NO_W_ID=" + wid + " and NO_D_ID=" + did + " and NO_O_ID=" + oid; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); cmd.CommandText = "select O_C_ID from ORDER where O_W_ID=" + wid + " and O_D_ID=" + did + " and O_ID=" + oid; Form1.RecordRequest(cmd, fid, tid); s = cmd.ExecuteReader(); s.Read(); ocid = (int)s[0]; s.Close(); cmd.CommandText = "update [ORDER] where O_W_ID=" + wid + " and O_D_ID=" + did + " and O_ID=" + oid + " set O_CARRIER_ID = " + carid; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); cmd.CommandText = "update ORDER_LINE where OL_W_ID=" + wid + " and OL_D_ID=" + did + " and OL_O_ID=" + oid + " set OL_DELIVERY_DATE='" + DateTime.Now.ToString("o") + "'"; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); decimal amount = 0.0M; cmd.CommandText = "select sum(OL_AMOUNT) from ORDER_LINE where OL_W_ID=" + wid + " and OL_D_ID=" + did + " and OL_O_ID=" + oid; s = cmd.ExecuteReader(); s.Read(); amount = util.GetDecimal(s[0]); s.Close(); cmd.CommandText = "update CUSTOMER where C_W_ID=" + wid + " and C_D_ID=" + did + " and C_ID=" + ocid + " set C_BALANCE =C_BALANCE+" + amount + ",C_DELIVERY_CNT=C_DELIVERY_CNT+1"; Form1.RecordRequest(cmd, fid, tid); s = cmd.ExecuteReader(); return(true); }
bool ExecNQ(string sql) { try { var cmd = db.CreateCommand(); cmd.Transaction = tr; cmd.CommandText = sql; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); return(false); } catch (Exception ex) { Form1.RecordResponse(ex, fid, tid); Form1.wconflicts++; } return(true); }
bool FetchDistrict(ref string mess) { var cmd = db.CreateCommand(); cmd.Transaction = tr; cmd.CommandText = "select D_TAX,D_NEXT_O_ID from DISTRICT where D_W_ID=" + wid + " and D_ID=" + did; var s = cmd.ExecuteReader(); if (!s.Read()) { mess = "No District " + did; s.Close(); return(true); } d_tax = (decimal)s[0]; o_id = (int)s[1]; Set(6, o_id); Set(132, DateTime.Now.ToString()); s.Close(); cmd.CommandText = "select W_TAX from WAREHOUSE where W_ID=" + wid; s = cmd.ExecuteReader(); if (!s.Read()) { mess = "No warehouse " + wid; s.Close(); return(true); } w_tax = (decimal)s[0]; Set(8, w_tax.ToString("F4").Substring(1)); Set(9, d_tax.ToString("F4").Substring(1)); s.Close(); cmd.CommandText = "update DISTRICT set D_NEXT_O_ID=" + (o_id + 1) + " where D_W_ID=" + wid + " and D_ID=" + did; Form1.RecordRequest(cmd, fid, tid); cmd.ExecuteNonQuery(); allhome = true; return(false); }