Example #1
0
        /// <summary>
        /// The common procedure what will save filled Repair 
        // and his used parts both Add mode and Edit mode.
        /// </summary>
        private void UpdateRepair(bool newRepair)
        {
            double Hours = 0.0;
            try
            {
                //				if(tbNotes.Text.Length > 0)
                //				{
                if (tbMinutes.Text.Length > 0 && Convert.ToDouble(tbMinutes.Text) >= 60)
                {
                    Header.ErrorMessage = _functions.ErrorMessage(206);
                    return;
                }
                if (tbHours.Text.Length > 0 || tbMinutes.Text.Length > 0)
                {
                    if (tbHours.Text.Length > 0) Hours += Convert.ToDouble(tbHours.Text);
                    if (tbMinutes.Text.Length > 0) Hours += Convert.ToDouble(tbMinutes.Text) / 60;
                }
                if (Hours >= 1000)
                {
                    Header.ErrorMessage = _functions.ErrorMessage(203);
                    return;
                }
                order = new clsWorkOrders();
                order.iOrgId = OrgId;
                order.iId = OrderId;
                order.sTypeService = sType;
                order.iItemId = ItemId;
                if (ServiceResult == "Repair")
                    order.iServiceResultId = (int)ServiceResults._Repaired;
                else
                    order.iServiceResultId = (int)ServiceResults._Replaced;
                if (Mode) // Add mode
                {
                    order.iRepairId = 0;
                }
                else // Edit mode
                    order.iRepairId = RepairId;

                if (RepairId == 0 && newRepair)
                {
                    order.iRepairId = preRepairId;
                    order.iInsert = true;
                }

                order.sRepairDesc = tbNotes.Text;
                order.iRepairItemId = Convert.ToInt32(ddlRepairItems.SelectedValue);
                order.iRepairCatId = Convert.ToInt32(ddlRepairCats.SelectedValue);
                if (order.UpdateRepair() == -1)
                {
                    Session["lastpage"] = sCurrentPage;
                    Session["error"] = _functions.ErrorMessage(128);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                RepairId = order.iRepairId.Value;
                // saving the parts for entered repair
                dtParts = (DataTable)ViewState["PartsUsed"];
                foreach (DataRow item in dtParts.Rows)
                {
                    if ((int)item["IsNew"] == 1)
                    {
                        order.cAction = "U";
                        order.iPartUsedId = 0;
                        order.iPartUsedQty = (int)item["Qty"];
                        order.sPartUsedStock = (string)item["Stock"];
                        order.sPartUsedDesc = (string)item["Desc"];
                        order.dmPartUsedCost = (decimal)item["Cost"];
                        order.PartsUsedDetails();
                    }
                    if ((int)item["IsDeleted"] == 1)
                    {
                        order.cAction = "D";
                        order.iPartUsedId = (int)item["Id"];
                        if (order.PartsUsedDetails() == -1)
                        {
                            Session["lastpage"] = sCurrentPage;
                            Session["error"] = _functions.ErrorMessage(125);
                            Response.Redirect("error.aspx", false);
                            return;
                        }
                    }
                }
                if (Mode && html_chNewRepair.Checked && sType == "II")
                {
                    order.iInspectItemId = ItemId;
                    foreach (RepeaterItem item in repReportedIssues.Items)
                    {
                        CheckBox cbTmp = (CheckBox)item.FindControl("cbIssue");
                        if (cbTmp.Checked && cbTmp.Enabled)
                        {
                            order.iReportedIssueId = Convert.ToInt32(cbTmp.Attributes["CommandArgument"]);
                            order.SetAssociationsIssue();
                        }
                    }
                }
                if (Hours > 0.0)
                {
                    user = new clsUsers();
                    user.iOrgId = OrgId;
                    user.iOrderId = OrderId;
                    if (user.GetTechnicianInfo() != -1)
                    {
                        order.cAction = "U";
                        order.iTimeLogId = 0;
                        order.iTechId = user.iId;
                        order.daStartTime = SqlDateTime.Null;
                        order.daStopTime = SqlDateTime.Null;
                        order.dmHours = Convert.ToDecimal(Hours);
                        order.dmHourlyRate = user.dmHourlyRate;
                        order.sNote = tbNotes.Text;
                        order.TimeLogDetails();
                    }
                }
                //				}
                //				else
                //					lblRequestor.Visible = true;
            }
            catch (FormatException fex)
            {
                Header.ErrorMessage = _functions.ErrorMessage(205);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (user != null)
                    user.Dispose();
                if (order != null)
                    order.Dispose();
            }
        }