Example #1
0
        public ActionResult SaveAppt()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strID      = Request.Form["hdnSvcid"];
            string strComment = Request.Form["txtComments"];

            try
            {
                svc_appointment sa;

                sa          = db.svc_appointments.Single(s => s.svc_id == Convert.ToInt32(strID));
                sa.comments = strComment;

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #2
0
        public ActionResult AddUser()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strUser = Request.Form["txtUserID"];
            string strPwd  = Request.Form["txtPassword"];

            try
            {
                Membership.CreateUser(strUser, strPwd, "*****@*****.**");

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #3
0
        public ActionResult ResetPassword()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strUser = Request.Form["hdnID"];
            string strPwd  = Request.Form["txtPassword"];

            try
            {
                string strRandomPwd = Membership.Provider.ResetPassword(strUser, null);

                Membership.Provider.ChangePassword(strUser, strRandomPwd, strPwd);

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #4
0
        public ActionResult SaveDateEdit()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strDt        = Request.Form["hdnSvcDate"];
            string strTotCrews  = Request.Form["ddlEditCrews"];
            string strSvcsSched = Request.Form["hdnSvcsSched"];
            bool   blnAvail     = Request.Form["chkAvail"] == "on" ? true : false;

            try
            {
                svc_schedule_day ssd;

                ssd           = db.svc_schedule_days.Single(s => s.svc_sched_dt == Convert.ToDateTime(strDt));
                ssd.available = blnAvail;
                ssd.tot_crews = Convert.ToInt32(strTotCrews);

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
        public ActionResult SaveAdmin()
        {
            string strRet;

            uls_dbDataContext db = new uls_dbDataContext();

            string adminType = Request.Form["hdnAdminType"];
            string strID;
            string strDescr     = Request.Form["txtDescription"];
            string strCompany   = Request.Form["ddlAdminCompany"];
            string strOperation = Request.Form["hdnAdminOper"];

            try
            {
                if (adminType == "AdminCertifications")
                {
                    qualification qual;

                    if (strOperation == "Add")
                    {
                        strID = Request.Form["txtID"];

                        qual             = new qualification();
                        qual.qualID      = strID;
                        qual.qualDesc    = strDescr;
                        qual.qualCompany = strCompany;


                        db.qualifications.InsertOnSubmit(qual);
                    }
                    else
                    {
                        strID         = Request.Form["hdnAdminID"];
                        qual          = db.qualifications.Single(q => q.qualID == strID);
                        qual.qualDesc = strDescr;
                    }
                }

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
        public ActionResult SaveWRAdmin()
        {
            string strRet;

            uls_dbDataContext db = new uls_dbDataContext();

            string strWRComment = Request.Form["txtWarnComments"];
            string strOperation = Request.Form["hdnWROper"];
            string strType      = Request.Form["hdnWRType"];
            string strDate      = Request.Form["dtWarning"];
            string strEmpID     = Request.Form["hdnWREmpID"];

            try
            {
                empWarnRecognition eWR;

                if (strOperation == "Add")
                {
                    eWR = new empWarnRecognition();
                    eWR.empQualWarnRecogDate = Convert.ToDateTime(strDate);
                    eWR.comment         = strWRComment;
                    eWR.employeeID      = Convert.ToInt32(strEmpID);
                    eWR.empWarnRecogFlg = Convert.ToChar(strType);


                    db.empWarnRecognitions.InsertOnSubmit(eWR);
                }
                else
                {
                    string strId = Request.Form["hdnEmailAdminID"];

                    eWR = db.empWarnRecognitions.Single(w => w.employeeID == Convert.ToInt32(strEmpID) && w.empQualWarnRecogDate == Convert.ToDateTime(strDate) && w.empWarnRecogFlg == Convert.ToChar(strType));

                    eWR.comment = strWRComment;
                }

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #7
0
        public ActionResult AddSvcDates()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strDtFrom   = Request.Form["dtDaysFrom"];
            string strDtTo     = Request.Form["dtDaysTo"];
            string strTotCrews = Request.Form["ddlCrews"];

            int intDaysToAdd = Convert.ToDateTime(strDtTo).Subtract(Convert.ToDateTime(strDtFrom)).Days;

            try
            {
                svc_schedule_day ssd;
                svc_schedule_day ssd2;

                int count;

                for (count = 0; count < intDaysToAdd; count = count + 1)
                {
                    ssd2 = db.svc_schedule_days.SingleOrDefault(s => s.svc_sched_dt == Convert.ToDateTime(strDtFrom).AddDays(count));
                    if (ssd2 != null)
                    {
                        continue;
                    }
                    ssd = new svc_schedule_day();
                    ssd.svc_sched_dt   = Convert.ToDateTime(strDtFrom).AddDays(count);
                    ssd.tot_crews      = Convert.ToInt32(strTotCrews);
                    ssd.available      = String.Format("{0:ddd}", ssd.svc_sched_dt) == "Sat" || String.Format("{0:ddd}", ssd.svc_sched_dt) == "Sun" ? false : true;
                    ssd.cur_svcs_sched = 0;
                    db.svc_schedule_days.InsertOnSubmit(ssd);
                }

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
        public ActionResult SaveEmailAdmin()
        {
            string strRet;

            uls_dbDataContext db = new uls_dbDataContext();

            string adminType    = Request.Form["hdnEmailAdminType"];
            string strEmail     = Request.Form["txtAdminEmail"];
            string strOperation = Request.Form["hdnEmailAdminOper"];

            try
            {
                if (adminType == "AdminEmailNotifications")
                {
                    qual_notification qual;

                    if (strOperation == "Add")
                    {
                        qual       = new qual_notification();
                        qual.email = strEmail;

                        db.qual_notifications.InsertOnSubmit(qual);
                    }
                    else
                    {
                        string strId = Request.Form["hdnEmailAdminID"];
                        qual       = db.qual_notifications.Single(q => q.id == Convert.ToInt32(strId));
                        qual.email = strEmail;
                    }
                }

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #9
0
        public ActionResult SaveContact()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strName         = Request.Form["txtName"];
            string strPhone        = Request.Form["txtPhone"];
            string strEmail        = Request.Form["txtEmail"];
            string strEmailNotify1 = Request.Form["txtEmailNotif1"];
            string strEmailNotify2 = Request.Form["txtEmailNotif2"];
            string strEmailNotify3 = Request.Form["txtEmailNotif3"];

            try
            {
                svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1);

                sc.contact_name   = strName;
                sc.contact_number = strPhone;
                sc.contact_email  = strEmail;
                sc.notify1_email  = strEmailNotify1;
                sc.notify2_email  = strEmailNotify2;
                sc.notify3_email  = strEmailNotify3;

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
        public ActionResult EditQualDlgX(int[] ids, FormCollection formValues)
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strEmployeeID = Request.Form["hdnEditQualEmpID"];
            string strOperation  = Request.Form["hdnEditEmpQualOper"];
            string strQualID     = Request.Form["hdnEditQualID"];

            string strTestDate   = Request.Form["dtTestDt"];
            string strExpireDate = Request.Form["dtExpireDt"];

            string strEvaluator = Request.Form["txtEvaluator"];

            foreach (int id in ids)
            {
            }


            try
            {
                empQual empQ;

                if (strOperation == "Edit")
                {
                    int intEmployeeID = Convert.ToInt32(strEmployeeID);
                    empQ = db.empQuals.Single(e => e.employeeId == intEmployeeID && e.qualId == strQualID);
                }
                else   // add
                {
                    empQ = new empQual();
                    string strCompany = Request.Form["ddlCompany"];
                    empQ.qualCompany = strCompany;
                    string strQualCd = Request.Form["ddlQualCodes"];
                    empQ.qualId     = strQualCd;
                    empQ.employeeId = Convert.ToInt32(strEmployeeID);
                }
                if (strOperation == "Edit" || strOperation == "Add")
                {
                    if (IsDate(strTestDate))
                    {
                        empQ.qualDate = Convert.ToDateTime(strTestDate);
                    }
                    if (IsDate(strExpireDate))
                    {
                        empQ.qualExpire = Convert.ToDateTime(strExpireDate);
                    }

                    empQ.evaluator = strEvaluator;

                    if (strOperation == "Add")
                    {
                        db.empQuals.InsertOnSubmit(empQ);
                    }
                }

                db.SubmitChanges();

                return(Content("Success"));
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                if (msg.IndexOf("PRIMARY") > 0)
                {
                    strRet = "Cannot add record. This qualification for this employee already exists!";
                }
                else
                {
                    strRet = msg;
                }

                return(Content(strRet));
            }
            finally
            {
                db.Dispose();
            }
        }
        public ActionResult EditEmp(Nullable <int> id, FormCollection formValues)
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strEmployeeID   = Request.Form["hdnEditID"];
            string strOperation    = Request.Form["hdnEditOper"];
            string strEmpID        = Request.Form["txtEmpID"];
            string strSSN          = Request.Form["txtSSN"];
            string strStatus       = Request.Form["ddlStatus"];
            string strLName        = Request.Form["txtLName"];
            string strMName        = Request.Form["txtMName"];
            string strFName        = Request.Form["txtFName"];
            string strSuffix       = Request.Form["txtSuffix"];
            string strAddress1     = Request.Form["txtAddress1"];
            string strAddress2     = Request.Form["txtAddress2"];
            string strCity         = Request.Form["txtCity"];
            string strState        = Request.Form["ddlState"];
            string strZip          = Request.Form["txtZip"];
            string strEmail        = "";
            string strComments     = Request.Form["txtEmpComment"];
            string strOQid         = Request.Form["txtOqid"];
            string strHomePhone    = Request.Form["txtHomePhone"];
            string strCellPhone    = Request.Form["txtCellPhone"];
            string strPayRate      = "";
            string strMVRcheckDt   = Request.Form["dtMVRcheckDt"];
            string strCBGcheckDt   = Request.Form["dtCBGcheckDt"];
            string strDandAcheckDt = Request.Form["dtDandAcheckDt"];
            string strJobClass     = Request.Form["ddlJobClass"];
            string strOpArea       = Request.Form["ddlOpAreas"];
            string strResult       = Request.Form["ddlResult"];
            string strBirthDt      = Request.Form["dtBirthDate"];
            string strMedCrdExpDt  = Request.Form["dtMedCrdExpDt"];
            string strDLNum        = Request.Form["txtDLNum"];
            string strDLState      = Request.Form["ddlDLState"];
            string strDLClass      = Request.Form["ddlDLClass"];
            string strDLExpDt      = Request.Form["dtDLExpDt"];


            try
            {
                employee employee;

                if (strOperation == "Edit")
                {
                    int intEmployeeID = Convert.ToInt32(strEmployeeID);
                    employee = db.employees.Single(e => e.employeeID == intEmployeeID);
                }
                else   // add
                {
                    employee = new employee();
                }
                if (strOperation == "Edit" || strOperation == "Add")
                {
                    employee.address1  = strAddress1;
                    employee.address2  = strAddress2;
                    employee.city      = strCity;
                    employee.email     = strEmail;
                    employee.empId     = strEmpID;
                    employee.comment   = strComments;
                    employee.empStatus = Convert.ToChar(strStatus);
                    employee.fname     = strFName;
                    employee.mname     = strMName;
                    employee.lname     = strLName;
                    employee.oqId      = strOQid;
                    employee.ssn       = strSSN;
                    employee.state     = strState;
                    employee.suffix    = strSuffix;
                    employee.zip       = strZip;
                    employee.homephone = strHomePhone;
                    employee.cellphone = strCellPhone;
                    employee.DLnum     = strDLNum;
                    employee.DLstate   = strDLState;

                    //Decimal decPayRate;

                    //if (Decimal.TryParse(strPayRate.Replace("$", ""), out decPayRate))
                    //{
                    //    employee.payRate = decPayRate;
                    //}

                    if (IsDate(strMVRcheckDt))
                    {
                        employee.MVRcheckDt = Convert.ToDateTime(strMVRcheckDt);
                    }

                    if (IsDate(strCBGcheckDt))
                    {
                        employee.CBGcheckDt = Convert.ToDateTime(strCBGcheckDt);
                    }

                    if (IsDate(strDandAcheckDt))
                    {
                        employee.DandAcheckDt = Convert.ToDateTime(strDandAcheckDt);
                    }

                    if (IsDate(strDLExpDt))
                    {
                        employee.DLexpDate = Convert.ToDateTime(strDLExpDt);
                    }

                    if (IsDate(strBirthDt))
                    {
                        employee.birthDate = Convert.ToDateTime(strBirthDt);
                    }

                    if (IsDate(strMedCrdExpDt))
                    {
                        employee.medicalCardExpDt = Convert.ToDateTime(strMedCrdExpDt);
                    }

                    employee.jobClass = strJobClass;
                    employee.oparea   = strOpArea;
                    if (strResult != "")
                    {
                        employee.DandAresult = Convert.ToChar(strResult);
                    }

                    if (strDLClass != "")
                    {
                        employee.DLclass = Convert.ToChar(strDLClass);
                    }

                    if (strOperation == "Add")
                    {
                        db.employees.InsertOnSubmit(employee);
                    }
                }

                db.SubmitChanges();

                return(Content("Success"));
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #12
0
        public ActionResult SaveUserRoles()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strUser     = Request.Form["hdnUID"];
            bool   bSecAdmin   = Request.Form["chkSecAdmin"] == "on" ? true : false;
            bool   bShopMgr    = Request.Form["chkShpMgr"] == "on" ? true : false;
            bool   bSvcForeman = Request.Form["chkSvcFrmn"] == "on" ? true : false;
            bool   bEmpQual    = Request.Form["chkEmpQual"] == "on" ? true : false;

            try
            {
                if (Roles.IsUserInRole(strUser, "sec_admin"))
                {
                    Roles.RemoveUserFromRole(strUser, "sec_admin");
                }

                if (Roles.IsUserInRole(strUser, "svc_foreman"))
                {
                    Roles.RemoveUserFromRole(strUser, "svc_foreman");
                }

                if (Roles.IsUserInRole(strUser, "shop_mgr"))
                {
                    Roles.RemoveUserFromRole(strUser, "shop_mgr");
                }

                if (Roles.IsUserInRole(strUser, "emp_qual"))
                {
                    Roles.RemoveUserFromRole(strUser, "emp_qual");
                }

                if (bSecAdmin == true)
                {
                    Roles.AddUserToRole(strUser, "sec_admin");
                }
                if (bShopMgr == true)
                {
                    Roles.AddUserToRole(strUser, "shop_mgr");
                }
                if (bSvcForeman == true)
                {
                    Roles.AddUserToRole(strUser, "svc_foreman");
                }

                if (bEmpQual == true)
                {
                    Roles.AddUserToRole(strUser, "emp_qual");
                }


                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #13
0
        public ActionResult SaveAdmin()
        {
            string strRet;
            string strAddType;

            strAddType = "NoAddType";

            uls_dbDataContext db = new uls_dbDataContext();

            string adminType    = Request.Form["hdnAdminType"];
            string strID        = Request.Form["hdnAdminID"];
            string strDescr     = Request.Form["txtDescription"];
            string strOperation = Request.Form["hdnAdminOper"];

            try
            {
                if (adminType == "AdminElectronicsTypes")
                {
                    electronics_type_avt eta;

                    if (strOperation == "Add")
                    {
                        eta           = new electronics_type_avt();
                        eta.type_id   = Convert.ToInt16(strID);
                        eta.type_desc = strDescr;


                        db.electronics_type_avts.InsertOnSubmit(eta);

                        strAddType = "YesAddType";
                    }
                    else
                    {
                        eta           = db.electronics_type_avts.Single(e => e.type_id == Convert.ToInt16(strID));
                        eta.type_desc = strDescr;
                    }
                }
                else if (adminType == "AdminElectronicsMakes")
                {
                    electronics_make_avt mka;

                    if (strOperation == "Add")
                    {
                        mka           = new electronics_make_avt();
                        mka.make_id   = Convert.ToInt16(strID);
                        mka.make_desc = strDescr;
                        db.electronics_make_avts.InsertOnSubmit(mka);
                    }
                    else
                    {
                        mka           = db.electronics_make_avts.Single(e => e.make_id == Convert.ToInt16(strID));
                        mka.make_desc = strDescr;
                    }
                }
                else if (adminType == "AdminElectronicsModels")
                {
                    electronics_model_avt mda;

                    if (strOperation == "Add")
                    {
                        mda            = new electronics_model_avt();
                        mda.model_id   = Convert.ToInt16(strID);
                        mda.model_desc = strDescr;
                        db.electronics_model_avts.InsertOnSubmit(mda);
                    }
                    else
                    {
                        mda            = db.electronics_model_avts.Single(e => e.model_id == Convert.ToInt16(strID));
                        mda.model_desc = strDescr;
                    }
                }

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet + "," + strAddType));
        }
Example #14
0
        public ActionResult EditElectronicsAsgn()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strElectronicsID = Request.Form["hdnAsgnEditID"];
            string strOperation     = Request.Form["hdnAsgnEditOper"];
            string strAsgnDt        = Request.Form["dtElectronicsAsgnDt"];
            string strRetDt         = Request.Form["dtElectronicsRetDt"];
            string strAsgnCond      = Request.Form["ddlAsgnCond"];
            string strRetCond       = Request.Form["ddlRetCond"];
            string strAsgndTo       = Request.Form["ddlAssignedTo"];
            string strComments      = Request.Form["txtElectronicsAsgnComments"];
            string strAsgnID        = Request.Form["hdnAsgnID"];

            try
            {
                electronics_assgn electonics_assign;

                electronic elctrnc = db.electronics.Single(a => a.electronics_id == strElectronicsID);

                if (strOperation == "Edit")
                {
                    int intAsgnID = Convert.ToInt32(strAsgnID);
                    electonics_assign = db.electronics_assgns.Single(a => a.assign_id == intAsgnID);
                }
                else   // add
                {
                    electonics_assign = new electronics_assgn();
                    electonics_assign.electronics_id = strElectronicsID;
                }
                if (strOperation == "Edit" || strOperation == "Add")
                {
                    electonics_assign.assigned_to = strAsgndTo;

                    if (IsDate(strAsgnDt))
                    {
                        electonics_assign.assigned_dt = Convert.ToDateTime(strAsgnDt);
                        elctrnc.assigned = true;
                    }
                    if (IsDate(strRetDt))
                    {
                        electonics_assign.return_dt = Convert.ToDateTime(strRetDt);
                        elctrnc.assigned            = false;
                    }
                    Int16 intAsignCond;
                    if (Int16.TryParse(strAsgnCond, out intAsignCond))
                    {
                        electonics_assign.asgn_condition_id = intAsignCond;
                    }
                    Int16 intRetCond;
                    if (Int16.TryParse(strRetCond, out intRetCond))
                    {
                        electonics_assign.ret_condition_id = intRetCond;
                    }

                    electonics_assign.comment_txt = strComments;


                    if (strOperation == "Add")
                    {
                        db.electronics_assgns.InsertOnSubmit(electonics_assign);
                    }
                }

                db.SubmitChanges();

                return(Content("Success"));
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #15
0
        public ActionResult EditElectronics()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strOperation = Request.Form["hdnEditOper"];
            string strElectronicsID;

            if (strOperation == "Edit")
            {
                strElectronicsID = Request.Form["hdnEditID"];
            }
            else
            {
                strElectronicsID = Request.Form["txtElectronicsID"];
            }

            string strYear       = Request.Form["txtElectronicsYear"];
            string strType       = Request.Form["ddlElectronicsType"];
            string strMake       = Request.Form["ddlElectronicsMake"];
            string strModel      = Request.Form["ddlElectronicsModel"];
            string strLoc        = Request.Form["ddlElectronicsLoc"];
            string strMngBy      = Request.Form["ddlElectronicsMngBy"];
            string strRegBy      = Request.Form["ddlElectronicsRegBy"];
            string strMngByDt    = Request.Form["dtElectronicsMngByDt"];
            string strSerialNum  = Request.Form["txtElectronicsSerialNum"];
            string strAirCardNum = Request.Form["txtElectronicsAirCardNum"];
            string strCost       = Request.Form["txtElectronicsCost"];
            string strStolen     = Request.Form["hdnElectronicsStolen"];
            string strInRepair   = Request.Form["hdnElectronicsInRepair"];
            string strTotaled    = Request.Form["hdnElectronicsTotaled"];
            string strUnknown    = Request.Form["hdnElectronicsUnknown"];
            string strComment    = Request.Form["txtElectronicsComment"];

            string strLogEntry = "";

            bool blnObsolete = false;

            try
            {
                electronic           eltrnc;
                electronic           eltrncCheck;
                electronics_edit_log logentry = new electronics_edit_log();

                logentry.user_id        = User.Identity.Name;
                logentry.edit_dt        = DateTime.Today;
                logentry.electronics_id = strElectronicsID;

                if (strOperation == "Edit")
                {
                    eltrnc = db.electronics.Single(e => e.electronics_id == strElectronicsID);
                }
                else   // add
                {
                    if (strElectronicsID.Length <= 0)
                    {
                        throw new Exception("Invalid ID specified.");
                    }

                    if (strRegBy.Length <= 0)
                    {
                        throw new Exception("No Division specified in Registered By field.");
                    }

                    eltrnc = new electronic();
                    eltrnc.electronics_id = strElectronicsID;
                    eltrnc.assigned       = false;


                    eltrncCheck = db.electronics.SingleOrDefault(e => e.electronics_id == eltrnc.electronics_id);
                    if (eltrncCheck != null)
                    {
                        throw new Exception("This ID already exists.");
                    }
                }
                if (strOperation == "Edit" || strOperation == "Add")
                {
                    if (strComment != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Comment", eltrnc.comment == null ? "" : eltrnc.comment.ToString(), strComment, strLogEntry);
                        }

                        eltrnc.comment = strComment;
                    }

                    Single sngCost;
                    if (strCost != null)
                    {
                        if (Single.TryParse(strCost.Replace("$", ""), out sngCost))
                        {
                            if (strOperation == "Edit")
                            {
                                strLogEntry = CheckEditField("Cost", eltrnc.cost == null ? "0" : eltrnc.cost.ToString(), strCost.Replace("$", ""), strLogEntry);
                            }
                            eltrnc.cost = sngCost;
                        }
                    }

                    if (strYear != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Purchase Year", eltrnc.year_pur == null ? "0" : eltrnc.year_pur.ToString(), strYear, strLogEntry);
                        }
                        eltrnc.year_pur = strYear;
                    }

                    if (strUnknown != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Unknown", eltrnc.unknown == true ? "on" : "off", strUnknown, strLogEntry);
                        }
                        eltrnc.unknown = strUnknown == "on" ? true : false;
                    }

                    if (strInRepair != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("In Repair", eltrnc.in_repair == true ? "on" : "off", strInRepair, strLogEntry);
                        }
                        eltrnc.in_repair = strInRepair == "on" ? true : false;
                    }

                    Int16 intMake;
                    if (Int16.TryParse(strMake, out intMake))
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Make ID", eltrnc.make_id == null ? "0" : eltrnc.make_id.ToString(), strMake, strLogEntry);
                        }
                        eltrnc.make_id = intMake;
                    }

                    if (strMngBy != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Managed By", eltrnc.managed_by == null ? "" : eltrnc.managed_by.ToString(), strMngBy, strLogEntry);
                        }
                        eltrnc.managed_by = strMngBy;
                    }

                    if (IsDate(strMngByDt))
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Managed By Date", eltrnc.managed_by_dt != null ? String.Format("{0:MM/dd/yyyy}", eltrnc.managed_by_dt) : "X", strMngByDt, strLogEntry);
                        }
                        eltrnc.managed_by_dt = Convert.ToDateTime(strMngByDt);
                    }

                    Int16 intModel;
                    if (Int16.TryParse(strModel, out intModel))
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Model ID", eltrnc.model_id == null ? "0" : eltrnc.model_id.ToString(), strModel, strLogEntry);
                        }
                        eltrnc.model_id = intModel;
                    }

                    if (strRegBy != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Registered By", eltrnc.registered_by == null ? "" : eltrnc.registered_by.ToString(), strRegBy, strLogEntry);
                        }
                        eltrnc.registered_by = strRegBy;
                    }

                    if (eltrnc.registered_by == null || eltrnc.registered_by.Length <= 0)
                    {
                        throw new Exception("Registered By must be specified.");
                    }

                    if (strStolen != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Stolen", eltrnc.stolen == true ? "on" : "off", strStolen, strLogEntry);
                            if (eltrnc.stolen == false && strStolen == "on")
                            {
                                blnObsolete = true;
                            }
                        }
                        eltrnc.stolen = strStolen == "on" ? true : false;
                    }

                    if (strTotaled != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Totaled", eltrnc.totaled == true ? "on" : "off", strTotaled, strLogEntry);
                            if (eltrnc.totaled == false && strTotaled == "on")
                            {
                                blnObsolete = true;
                            }
                        }
                        eltrnc.totaled = strTotaled == "on" ? true : false;
                    }

                    Int16 intType;
                    if (Int16.TryParse(strType, out intType))
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Type ID", eltrnc.type_id == null ? "" : eltrnc.type_id.ToString(), strType, strLogEntry);
                        }
                        eltrnc.type_id = intType;
                    }

                    if (strSerialNum != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Serial Num", eltrnc.serial_num == null ? "" : eltrnc.serial_num.ToString(), strSerialNum, strLogEntry);
                        }
                        eltrnc.serial_num = strSerialNum;
                    }

                    if (strAirCardNum != null)
                    {
                        if (strOperation == "Edit")
                        {
                            string strNumStripped = System.Text.RegularExpressions.Regex.Replace(strAirCardNum, "\\D", "");
                            strLogEntry = CheckEditField("Air Card Num", eltrnc.air_card_num == null ? "" : eltrnc.air_card_num.ToString(), strAirCardNum, strLogEntry);
                        }
                        eltrnc.air_card_num = strAirCardNum;
                    }

                    if (eltrnc.serial_num != null && eltrnc.serial_num.Length > 0)
                    {
                        eltrncCheck = db.electronics.SingleOrDefault(e => e.serial_num == eltrnc.serial_num);
                        if (eltrncCheck != null)
                        {
                            if (eltrnc.electronics_id != eltrncCheck.electronics_id)
                            {
                                throw new Exception("Serial Number already exists for: " + eltrncCheck.electronics_id);
                            }
                        }
                    }

                    if (strLoc != null)
                    {
                        if (strOperation == "Edit")
                        {
                            strLogEntry = CheckEditField("Location", eltrnc.location == null ? "" : eltrnc.location.ToString(), strLoc, strLogEntry);
                        }
                        eltrnc.location = strLoc;
                    }

                    if (strOperation == "Add")
                    {
                        strLogEntry = "Record Added.";
                        db.electronics.InsertOnSubmit(eltrnc);
                    }
                }

                if (strLogEntry != "")
                {
                    if (strOperation == "Edit")
                    {
                        logentry.edit_change = "Modified: " + strLogEntry;
                    }
                    else
                    {
                        logentry.edit_change = strLogEntry;
                    }
                    db.electronics_edit_logs.InsertOnSubmit(logentry);
                }

                db.SubmitChanges();

                if (blnObsolete == true && Convert.ToString(Session["division"]) == "ULS-PA")
                {
                    db.UpdateObsoleteId(strElectronicsID);
                }

                return(Content("Success" + "," + Session["division"]));
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;

                return(Content(strRet + "," + ""));
            }
            finally
            {
                db.Dispose();
            }
        }
Example #16
0
        public ActionResult SaveDate()
        {
            string            strRet;
            uls_dbDataContext db = new uls_dbDataContext();

            string strDateForm = Request.Form["AvailableDates"];

            string strDate = strDateForm.Substring(4).Trim();

            string strDateFormatted = strDateForm.Substring(0, 3) + ", " + strDate;

            string resched = Convert.ToString(Session["ReSchedule"]);


            try
            {
                svc_schedule_day ssa = db.svc_schedule_days.SingleOrDefault(s => s.svc_sched_dt == Convert.ToDateTime(strDate));

                if (ssa.cur_svcs_sched >= ssa.tot_crews)
                {
                    Session["SaveResultName"] = "Sorry " + Session["FName"] + " " + Session["LName"] + "!";
                    throw new Exception(strDateFormatted + " is no longer available. Please select another date.");
                }

                svc_appointment sa2 = db.svc_appointments.SingleOrDefault(a => a.home_phone == Convert.ToString(Session["txtHomePhone"]) && a.svc_date > DateTime.Now);

                if (sa2 != null && resched == "No")
                {
                    svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1);

                    string strName  = sc.contact_name;
                    string strPhone = sc.contact_number;
                    string strEmail = sc.contact_email;

                    Session["SaveResultName"] = "Sorry " + Session["FName"] + " " + Session["LName"] + "!";
                    throw new Exception("You were already scheduled for service. Your service day is currently set for " + String.Format("{0:MM/dd/yyyy}", sa2.svc_date) +
                                        ". + If you need to reschedule please call or email " + strName + " (" + strEmail + ")" + " at " + strPhone + " or return to the Save Contact Page and click the Reschedule link.");
                }


                if (resched == "Yes")
                {
                    svc_schedule_day ssa2 = db.svc_schedule_days.SingleOrDefault(s => s.svc_sched_dt == sa2.svc_date);
                    ssa2.cur_svcs_sched = ssa2.cur_svcs_sched - 1;
                }

                if (resched == "Yes")
                {
                    Session["SaveResultName"] = "Sorry " + Session["FName"] + " " + Session["LName"] + "!";
                    throw new Exception("To reschedule an appointment you must supply ahome telephone number when entering contact info.");
                }

                svc_appointment sa = new svc_appointment();

                IEnumerable <int> crewNums = db.GetCrewNums(Convert.ToDateTime(strDate));

                bool bHit    = false;
                int  ourCrew = 0;

                for (int i = 1; i <= ssa.tot_crews; i++)
                {
                    foreach (int crew in crewNums)
                    {
                        if (i == crew)
                        {
                            bHit = true;
                        }
                    }

                    if (bHit == false)
                    {
                        ourCrew = i;
                        break;
                    }

                    bHit = false;
                }


                sa.city           = Convert.ToString(Session["txtCity"]);
                sa.crew           = ourCrew;
                sa.email          = Convert.ToString(Session["txtEmail"]);
                sa.first_name     = Convert.ToString(Session["FName"]);
                sa.last_name      = Convert.ToString(Session["LName"]);
                sa.home_phone     = Convert.ToString(Session["txtHomePhone"]);
                sa.other_phone    = Convert.ToString(Session["txtOtherPhone"]);
                sa.state          = Convert.ToString(Session["ddlState"]);
                sa.street_address = Convert.ToString(Session["txtAddress"]);
                sa.svc_date       = Convert.ToDateTime(strDate);
                sa.zip            = Convert.ToString(Session["txtZip"]);
                sa.comments       = Convert.ToString(Session["txtNotes"]);

                int intForemanID = db.GetForemanID(ourCrew);

                sa.foreman_id = intForemanID;

                db.svc_appointments.InsertOnSubmit(sa);

                ssa.cur_svcs_sched = crewNums.Count() + 1;

                if (resched == "Yes")
                {
                    db.svc_appointments.DeleteOnSubmit(sa2);
                    sa.reschedule = true;
                }
                else
                {
                    sa.reschedule = false;
                }

                db.SubmitChanges();

                strRet = "Thanks " + Session["FName"] + " " + Session["LName"] + "!";

                Session["SaveResultName"] = strRet;

                Session["SaveResultMsg"] = "Your service renewal on " + strDateFormatted + " has been successfully scheduled. You will receive an email reminder the day before your service date.";

                Session["ShowReturnLink"] = "No";

                SendEmailNofication(strDate);

                return(RedirectToAction("SvcDateResult"));
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                Session["SaveResultMsg"] = msg;

                if (msg.Contains("available"))
                {
                    return(RedirectToAction("SelectSvcDate"));
                }
                else
                {
                    Session["ShowReturnLink"] = "Yes";

                    return(RedirectToAction("SvcDateResult"));
                }
            }
            finally
            {
                db.Dispose();
            }
        }