コード例 #1
0
        /// <summary>
        /// The commmon procedure for saving of selected items
        /// </summary>
        private void SaveChangedItems()
        {
            try
            {
                int ServiceCheckId;
                int ServiceResultId;
                int newServiceCheckId = 0;
                int newServiceResultId = 0;
                int InspectItemId;
                bool bOkay, bFair, bRN, bNS, bRepair, bReplace;

                order = new clsWorkOrders();
                order.iOrgId = OrgId;
                order.iId = OrderId;

                foreach(RepeaterItem item in repInspectItems.Items)
                {
                    newServiceCheckId = 0;
                    newServiceResultId = 0;

                    // old data
                    ServiceCheckId = Convert.ToInt32(((Label)item.FindControl("ServiceCheckId")).Text);
                    ServiceResultId = Convert.ToInt32(((Label)item.FindControl("ServiceResultId")).Text);
                    InspectItemId = Convert.ToInt32(((LinkButton)item.FindControl("lbRepair")).CommandArgument);

                    // new data
                    bOkay = ((CheckBox)item.FindControl("_chOkay")).Checked;
                    bFair = ((CheckBox)item.FindControl("_chFair")).Checked;
                    bRN = ((CheckBox)item.FindControl("_chRNeeded")).Checked;
                    bNS = ((CheckBox)item.FindControl("_cbNoService")).Checked;
                    bRepair = ((CheckBox)item.FindControl("_cbRepaired")).Checked;
                    bReplace = ((CheckBox)item.FindControl("_cbReplaced")).Checked;

                    // comparing data
                    if(bOkay)newServiceCheckId = (int)ServiceChecks._CheckOK;
                    if(bFair)newServiceCheckId = (int)ServiceChecks._CheckFair;
                    if(bRN)newServiceCheckId = (int)ServiceChecks._CheckRepairs_Needed;
                    if(bNS)newServiceResultId = 0;
                    if(bRepair)newServiceResultId = (int)ServiceResults._Repaired;
                    if(bReplace)newServiceResultId = (int)ServiceResults._Replaced;

                    if(ServiceCheckId == newServiceCheckId && ServiceResultId == newServiceResultId)
                        ;
                    else
                    { // if the statuses were changed
                        if(ServiceResultId > 0 && newServiceResultId > 0)
                            ;
                        else // if status wasn't changed to No Service
                        {
                            // to set the changes into database
                            order.iInspectItemId = InspectItemId;
                            order.iServiceResultId = ServiceResultId;
                            if(newServiceCheckId == 0)
                                order.iServiceCheckId = SqlInt32.Null;
                            else
                                order.iServiceCheckId = newServiceCheckId;
                            if(order.SetInspectItemChecks() == -1)
                            {
                                Session["lastpage"] = "wo_viewCompleteInspection.aspx?id=" + OrderId.ToString() + "&inspectid=" + InspectId.ToString();
                                Session["error"] = _functions.ErrorMessage(121);
                                Response.Redirect("error.aspx", false);
                                return;
                            }
                        }
                    }
                }

            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if(order != null)
                    order.Dispose();
            }
        }