/// <summary> /// From the client selected create a temporary table from the items in the order /// Then diosplay another for for the user to select how to close the order /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnOrderDelivered_Click(object sender, EventArgs e) { // General VARs OrderHeaderData _OrderHeaderData = Get_dvOrderHeaderData(false); TempOrdersData _TempOrdersData = new TempOrdersData(); TempOrdersDAL _TempOrdersDAL = new TempOrdersDAL(); // DELETE data from TempOrdersHeaderTblData if (!_TempOrdersDAL.KillTempOrdersData()) { ltrlStatus.Text = "Error deleting Temp Table"; } // add parameters in the order they appear in the update command // first summary / header data _TempOrdersData.HeaderData.CustomerID = _OrderHeaderData.CustomerID; _TempOrdersData.HeaderData.OrderDate = _OrderHeaderData.OrderDate; _TempOrdersData.HeaderData.RoastDate = _OrderHeaderData.RoastDate; _TempOrdersData.HeaderData.RequiredByDate = _OrderHeaderData.RequiredByDate; _TempOrdersData.HeaderData.ToBeDeliveredByID = Convert.ToInt32(_OrderHeaderData.ToBeDeliveredBy); _TempOrdersData.HeaderData.Confirmed = _OrderHeaderData.Confirmed; _TempOrdersData.HeaderData.Done = _OrderHeaderData.Done; _TempOrdersData.HeaderData.Notes = _OrderHeaderData.Notes; //_TempOrdersData.HeaderData.CustomerID = Convert.ToInt32(dvOrderHeaderGetDDLControlSelectedValue("ddlContacts")); //_TempOrdersData.HeaderData.OrderDate = Convert.ToDateTime(dvOrderHeaderGetLabelValue("lblOrderDate")); //_TempOrdersData.HeaderData.RoastDate = Convert.ToDateTime(dvOrderHeaderGetLabelValue("lblRoastDate")); //_TempOrdersData.HeaderData.RequiredByDate = Convert.ToDateTime(dvOrderHeaderGetLabelValue("lblRequiredByDate")); //_TempOrdersData.HeaderData.ToBeDeliveredByID = Convert.ToInt32(dvOrderHeaderGetDDLControlSelectedValue("ddlToBeDeliveredBy")); //_TempOrdersData.HeaderData.Confirmed = dvOrderHeaderGetCheckBoxValue("cbxConfirmed"); //_TempOrdersData.HeaderData.Done = dvOrderHeaderGetCheckBoxValue("cbxDone"); //_TempOrdersData.HeaderData.Notes = dvOrderHeaderGetLabelValue("lblNotes"); // now the line data (the TO header is set when we add both using the one class TempOrders ItemTypeTbl _ItemType = new ItemTypeTbl(); foreach (GridViewRow _gv in gvOrderLines.Rows) { TempOrdersLinesTbl _LineData = new TempOrdersLinesTbl(); DropDownList _gvItemDesc = (DropDownList)_gv.FindControl("ddlItemDesc"); Label _gvItemQty = (Label)_gv.FindControl("lblQuantityOrdered"); DropDownList _gvItemPackaging = (DropDownList)_gv.FindControl("ddlPackaging"); Label _gvOrderID = (Label)_gv.FindControl("lblOrderID"); _LineData.ItemID = Convert.ToInt32(_gvItemDesc.SelectedValue); _LineData.Qty = Convert.ToDouble(_gvItemQty.Text); _LineData.PackagingID = Convert.ToInt32(_gvItemPackaging.SelectedValue); _LineData.ServiceTypeID = _ItemType.GetServiceID(_LineData.ItemID); _LineData.OriginalOrderID = Convert.ToInt64(_gvOrderID.Text); _TempOrdersData.OrdersLines.Add(_LineData); } // now add all the data to the database _TempOrdersDAL.Insert(_TempOrdersData); // open new form with database, p Response.Redirect("OrderDone.aspx"); }
//protected void MarkTempOrdersItemsAsDone(long pCustomerID) //{ // string _SQLUpdate = "UPDATE OrdersTbl SET OrdersTbl.Done = True WHERE CustomderId = " + pCustomerID.ToString() + // "AND EXISTS (SELECT RequiredByDate FROM TempOrdersHeaderTbl " + // " WHERE (RequiredByDate = OrdersTbl.RequiredByDate))"; // TrackerDb _TrackerDb = new TrackerDb(); // _TrackerDb.ExecuteNonQuerySQL(_SQLUpdate); // // ResetCustomerReminderCount(pCustomerId); // //''''''''''''' // //' mark orders as done - should do this last // //''' // //lblStatus.Caption = "Marking orders as done" // //dbs.Execute ("UPDATE OrdersTbl SET OrdersTbl.Done = True " + _ // // "WHERE (((Exists (Select TempOrdersTbl.OrderId from TempOrdersTbl where " + _ // // "TempOrdersTbl.OrderId = OrdersTbl.OrderId))<>False))") // //''''''' // //' Resetting count and enable, only if coffee item // //' // //dbs.Execute ("UPDATE DISTINCTROW CustomersTbl SET ReminderCount = 0, enabled = True WHERE CustomerID=" + lblCustomerID.Caption) //} // Logic for processing order as done: // 1. move items consumed from temp aable to the items consumed for the contact // 2. using the summary of the data on the form do calculations around predictions // on when the contact needs items again. // 3. Notify client of items deliverred (add option to contacts table) // 4. return to the previous page. protected void btnDone_Click(object sender, EventArgs e) { const long MAXQTYINSTOCK = 50; TrackerTools _TrackerTools = new TrackerTools(); _TrackerTools.SetTrackerSessionErrorString(string.Empty); Label _CustomerIDLabel = (Label)(fvOrderDone.FindControl("CustomerIDLabel")); Label _CustomerNameLabel = (Label)(fvOrderDone.FindControl("CompanyNameLabel")); long _CustomerID = Convert.ToInt64(_CustomerIDLabel.Text); TextBox _OrderDateLabel = (TextBox)(fvOrderDone.FindControl("ByDateTextBox")); DateTime _OrderDate = Convert.ToDateTime(_OrderDateLabel.Text); double _CoffeeStock = 0; // store the current data for display later: ClientUsageTbl _OriginalUsageDAL = new ClientUsageTbl(); ClientUsageTbl _OriginalUsageData = _OriginalUsageDAL.GetUsageData(_CustomerID); if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString())) { Response.Write(_TrackerTools.GetTrackerSessionErrorString()); } TempOrdersDAL _TempOrdersDAL = new TempOrdersDAL(); // bool _HasCoffeeInTempOrder = _TempOrdersDAL.HasCoffeeInTempOrder(); if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString())) { Response.Write(_TrackerTools.GetTrackerSessionErrorString()); } /* NEED TO ADD Code to check for zzname */ // check cup count not in wrong place if ((tbxStock.Text.Length > 0) && (Convert.ToInt64(tbxStock.Text) > MAXQTYINSTOCK)) { ltrlStatus.Text = "<b>The stock quantity appears very high please check that you have enterred the correct value in kilograms.</b>"; } else { _CoffeeStock = String.IsNullOrEmpty(tbxStock.Text) ? 0 : Convert.ToDouble(tbxStock.Text); // First we must get the latest cup count ltrlStatus.Text = "Calculating the latest cup count"; GeneralTrackerDbTools _GeneralTrackerDb = new GeneralTrackerDbTools(); GeneralTrackerDbTools.LineUsageData _LatestCustomerData = _GeneralTrackerDb.GetLatestUsageData(_CustomerID, TrackerTools.CONST_SERVTYPECOFFEE); if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString())) { Response.Write(_TrackerTools.GetTrackerSessionErrorString()); } bool _bIsActual = (tbxCount.MaxLength > 0); // if there is a cup count long _lCupCount = 0; if (tbxCount.MaxLength > 0) { _lCupCount = Convert.ToInt64(tbxCount.Text); } // Calculate the cup count if we do not have it on the form or they entered a value that makes no sense if ((_lCupCount < 1) || (_lCupCount < _LatestCustomerData.LastCount)) { ltrlStatus.Text = "Calculating the latest est cup count"; _lCupCount = _GeneralTrackerDb.CalcEstCupCount(_CustomerID, _LatestCustomerData, _HasCoffeeInTempOrder); _bIsActual = false; } //' add items to consumption log _lCupCount = AddItemsToClientUsageTbl(_CustomerID, _bIsActual, _lCupCount, _CoffeeStock, _OrderDate); // update the last cup count for the client if (!_OriginalUsageDAL.UpdateUsageCupCount(_CustomerID, _lCupCount)) { ltrlStatus.Text = "error updating last count"; } // now update the predictions _GeneralTrackerDb.UpdatePredictions(_CustomerID, _lCupCount); // update all items in the order table as done that are done _TempOrdersDAL.MarkTempOrdersItemsAsDone(); // reset count and enable client _GeneralTrackerDb.ResetCustomerReminderCount(_CustomerID, _HasCoffeeInTempOrder); // destroy the temp table that we used to create this temp orders _TempOrdersDAL.KillTempOrdersData(); ShowResults(_CustomerNameLabel.Text, _CustomerID, _OriginalUsageData); } }
//protected void MarkTempOrdersItemsAsDone(long pCustomerID) //{ // string _SQLUpdate = "UPDATE OrdersTbl SET OrdersTbl.Done = True WHERE CustomderId = " + pCustomerID.ToString() + // "AND EXISTS (SELECT RequiredByDate FROM TempOrdersHeaderTbl " + // " WHERE (RequiredByDate = OrdersTbl.RequiredByDate))"; // TrackerDb _TrackerDb = new TrackerDb(); // _TrackerDb.ExecuteNonQuerySQL(_SQLUpdate); // // ResetCustomerReminderCount(pCustomerId); // //''''''''''''' // //' mark orders as done - should do this last // //''' // //lblStatus.Caption = "Marking orders as done" // //dbs.Execute ("UPDATE OrdersTbl SET OrdersTbl.Done = True " + _ // // "WHERE (((Exists (Select TempOrdersTbl.OrderId from TempOrdersTbl where " + _ // // "TempOrdersTbl.OrderId = OrdersTbl.OrderId))<>False))") // //''''''' // //' Resetting count and enable, only if coffee item // //' // //dbs.Execute ("UPDATE DISTINCTROW CustomersTbl SET ReminderCount = 0, enabled = True WHERE CustomerID=" + lblCustomerID.Caption) //} // Logic for processing order as done: // 1. move items consumed from temp aable to the items consumed for the contact // 2. using the summary of the data on the form do calculations around predictions // on when the contact needs items again. // 3. Notify client of items deliverred (add option to contacts table) // 4. return to the previous page. protected void btnDone_Click(object sender, EventArgs e) { const long MAXQTYINSTOCK = 50; TrackerTools _TrackerTools = new TrackerTools(); _TrackerTools.SetTrackerSessionErrorString(string.Empty); Label _CustomerIDLabel = (Label)(fvOrderDone.FindControl("CustomerIDLabel")); Label _CustomerNameLabel = (Label)(fvOrderDone.FindControl("CompanyNameLabel")); long _CustomerID = Convert.ToInt64(_CustomerIDLabel.Text); TextBox _OrderDateLabel = (TextBox)(fvOrderDone.FindControl("ByDateTextBox")); DateTime _OrderDate = Convert.ToDateTime(_OrderDateLabel.Text); double _CoffeeStock = 0; // store the current data for display later: ClientUsageTbl _OriginalUsageDAL = new ClientUsageTbl(); ClientUsageTbl _OriginalUsageData = _OriginalUsageDAL.GetUsageData(_CustomerID); if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString())) { Response.Write(_TrackerTools.GetTrackerSessionErrorString()); } TempOrdersDAL _TempOrdersDAL = new TempOrdersDAL(); // bool _HasCoffeeInTempOrder = _TempOrdersDAL.HasCoffeeInTempOrder(); if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString())) { Response.Write(_TrackerTools.GetTrackerSessionErrorString()); } /* NEED TO ADD Code to check for zzname */ // check cup count not in wrong place if ((tbxStock.Text.Length > 0) && (Convert.ToDouble(tbxStock.Text) > MAXQTYINSTOCK)) { showMessageBox _MsgBox = new showMessageBox(this.Page, "Stock seems high", "The stock quantity appears very high please check that you have enterred the correct value in kilograms.</b>"); } else { _CoffeeStock = String.IsNullOrEmpty(tbxStock.Text) ? 0 : Math.Round(Convert.ToDouble(tbxStock.Text), 2); // First we must get the latest cup count ltrlStatus.Text = "Calculating the latest cup count"; GeneralTrackerDbTools _GeneralTrackerDb = new GeneralTrackerDbTools(); GeneralTrackerDbTools.LineUsageData _LatestCustomerData = _GeneralTrackerDb.GetLatestUsageData(_CustomerID, TrackerTools.CONST_SERVTYPECOFFEE); if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString())) { showMessageBox _smb = new showMessageBox(this.Page, "Tracker Session Error", _TrackerTools.GetTrackerSessionErrorString()); } bool _bIsActual = (tbxCount.MaxLength > 0); // if there is a cup count long _lCupCount = 0; if (tbxCount.MaxLength > 0) { _lCupCount = Convert.ToInt64(tbxCount.Text); } // Calculate the cup count if we do not have it on the form or they entered a value that makes no sense if ((_lCupCount < 1) || (_lCupCount < _LatestCustomerData.LastCount)) { ltrlStatus.Text = "Calculating the latest est cup count"; _lCupCount = _GeneralTrackerDb.CalcEstCupCount(_CustomerID, _LatestCustomerData, _HasCoffeeInTempOrder); _bIsActual = false; } // clear any repairs that may have been logged RepairsTbl _Repairs = new RepairsTbl(); _Repairs.SetStatusDoneByTempOrder(); //' add items to consumption log _lCupCount = AddItemsToClientUsageTbl(_CustomerID, _bIsActual, _lCupCount, _CoffeeStock, _OrderDate); // update the last cup count for the client if (!_OriginalUsageDAL.UpdateUsageCupCount(_CustomerID, _lCupCount)) { showMessageBox _smb = new showMessageBox(this.Page, "Error", "Error updating last count"); ltrlStatus.Text = "error updating last count"; } // now update the predictions _GeneralTrackerDb.UpdatePredictions(_CustomerID, _lCupCount); // update all items in the order table as done that are done _TempOrdersDAL.MarkTempOrdersItemsAsDone(); // reset count and enable client _GeneralTrackerDb.ResetCustomerReminderCount(_CustomerID, _HasCoffeeInTempOrder); if (_HasCoffeeInTempOrder) { _GeneralTrackerDb.SetClientCoffeeOnlyIfInfo(_CustomerID); } // may need to add another check here to handle if they have ordered maintenance stuff. switch (rbtnSendConfirm.SelectedValue) { case "none": break; case "postbox": SendDeliveredEmail(_CustomerID, "placed your order in the your post box."); break; case "dispatched": SendDeliveredEmail(_CustomerID, "dispatched you order."); break; case "done": SendDeliveredEmail(_CustomerID, "delivered your order and it has signed for."); break; default: break; } // destroy the temp table that we used to create this temp orders _TempOrdersDAL.KillTempOrdersData(); ShowResults(_CustomerNameLabel.Text, _CustomerID, _OriginalUsageData); } }