public static FleetRequest GetFleetServeDetails(string service_ref)
        {
            var objReturn = new FleetRequest();

            using (var con = new MySqlConnection(ConnectionHelper.MyDirectoryConnection()))
            {
                con.Open();
                var cmd = new MySqlCommand();
                cmd = new MySqlCommand("SELECT * FROM fleet_serve " +
                                       "WHERE service_ref=@service_ref", con);
                cmd.Parameters.AddWithValue("@service_ref", service_ref);
                var dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    objReturn = new FleetRequest
                    {
                        plate     = dr["plate"].ToString(),
                        start_km  = int.Parse(dr["start_km"].ToString()),
                        end_km    = int.Parse(dr["end_km"].ToString()),
                        sar       = int.Parse(dr["sar"].ToString()),
                        complaint = dr["complaint"].ToString(),
                        note      = dr["note"].ToString(),
                    };
                }
            }

            return(objReturn);
        }
        public FleetNotification GetRequestsForApprovals(string line_manager_id)
        {
            var notificationReturn = new FleetNotification();
            var ctr = 0;

            if (!line_manager_id.Contains("@"))
            {
                line_manager_id = line_manager_id + "@kaec.net";
            }
            var eecEmployees = new EECEmployee();

            line_manager_id = eecEmployees.GetEmployeeDetails(line_manager_id)[0].emp_ID;

            var tempList = new List <FleetRequest>();

            using (var con = new MySqlConnection(ConnectionHelper.MyDirectoryConnection()))
            {
                con.Open();
                var cmd = new MySqlCommand();
                cmd = new MySqlCommand("SELECT * FROM fleet_request " +
                                       "WHERE code='0' AND randomize!='9' ORDER BY from_date DESC", con);
                cmd.Parameters.AddWithValue("@line_manager_id", line_manager_id);

                using (var dr = cmd.ExecuteReader())
                {
                    tempList = FleetRequest.PopulateFleetRequest(dr);

                    dr.Close();
                }

                con.Close();
            }


            foreach (var items in tempList)
            {
                var result = new List <EECEmployee>();
                result = eecEmployees.GetEmployeeDetails(items.emp_id);

                if (result.Count == 0)
                {
                    var nonEEC = new NonEECEmployee();
                    var nonEECEmployeeDetails = nonEEC.GetEmployeeDetails(items.emp_id);

                    result.Add(new EECEmployee
                    {
                        line_Manager_No = nonEECEmployeeDetails.manager_id
                    });
                }

                else
                {
                    result = eecEmployees.GetEmployeeDetails(items.emp_id);
                }

                if (result.Count != 0)
                {
                    foreach (var employeeDetails in result)
                    {
                        if (employeeDetails.line_Manager_No == line_manager_id)
                        {
                            ctr = ctr + 1;
                            break;
                        }
                    }
                }
            }

            notificationReturn = new FleetNotification
            {
                Notifications = ctr,
                Tag           = "fleet approvals",
            };

            return(notificationReturn);
        }
        public FleetRequest GetRequestsDetails(string service_ref)
        {
            var objReturn    = new FleetRequest();
            var eecEmployees = new EECEmployee();

            using (var con = new MySqlConnection(ConnectionHelper.MyDirectoryConnection()))
            {
                con.Open();
                var cmd = new MySqlCommand();
                cmd = new MySqlCommand("SELECT * FROM fleet_request " +
                                       "WHERE service_ref=@service_ref", con);
                cmd.Parameters.AddWithValue("@service_ref", service_ref);
                var dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    var fleetServeDetails = GetFleetServeDetails(dr["service_ref"].ToString());

                    var result = new List <EECEmployee>();

                    result = eecEmployees.GetEmployeeDetails(dr["emp_id"].ToString());

                    if (result.Count == 0)
                    {
                        var nonEEC = new NonEECEmployee();
                        var nonEECEmployeeDetails = nonEEC.GetEmployeeDetails(dr["emp_id"].ToString());

                        result.Add(new EECEmployee
                        {
                            cost_Center       = nonEECEmployeeDetails.cost_center,
                            department        = nonEECEmployeeDetails.department,
                            e_Mail            = nonEECEmployeeDetails.email,
                            line_Manager_Name = nonEECEmployeeDetails.manager,
                            line_Manager_No   = nonEECEmployeeDetails.manager_id
                        });
                    }


                    else
                    {
                        result = eecEmployees.GetEmployeeDetails(dr["emp_id"].ToString());
                    }

                    if (result.Count != 0)
                    {
                        foreach (var employeeDetails in result)
                        {
                            //if (employeeDetails.line_Manager_No == line_manager_id)
                            //{
                            var driverName   = string.Empty;
                            var driverMobile = string.Empty;

                            var driverDetails = eecEmployees.GetEmployeeDetails(dr["driver_id"].ToString());

                            foreach (var details in driverDetails)
                            {
                                driverName   = dr["nature"].ToString().ToLower().Contains("chauffeur") ? "WPS Driver" : details.employee_Name_English;
                                driverMobile = details.mobile;
                            }

                            objReturn = new FleetRequest
                            {
                                cost_center        = employeeDetails.cost_Center,
                                department         = employeeDetails.department,
                                driver             = driverName,
                                driver_mobile      = driverMobile,
                                email              = employeeDetails.e_Mail,
                                line_manager       = employeeDetails.line_Manager_Name,
                                line_manager_email = employeeDetails.line_Manager_Email,
                                line_manager_id    = employeeDetails.line_Manager_No,

                                code    = dr["code"].ToString(),
                                contact = dr["contact"].ToString(),

                                driver_id = dr["driver_id"].ToString(),

                                drop = dr["drop"].ToString(),

                                emp_id = dr["emp_id"].ToString(),

                                from_date     = Convert.ToDateTime(dr["from_date"].ToString()),
                                grade         = int.Parse(dr["grade"].ToString()),
                                id            = int.Parse(dr["id"].ToString()),
                                ip            = dr["ip"].ToString(),
                                justification = dr["justification"].ToString(),

                                name   = dr["name"].ToString(),
                                nature = dr["nature"].ToString(),

                                pax  = dr["pax"].ToString(),
                                pick = dr["pick"].ToString(),

                                random    = dr["random"].ToString(),
                                randomize = dr["randomize"].ToString(),

                                remarks = dr["remarks"].ToString(),

                                service_ref = dr["service_ref"].ToString(),
                                session     = dr["session"].ToString(),

                                specific_pick = dr["specific_pick"].ToString(),

                                timestamp = dr["timestamp"].ToString(),
                                to_date   = nature.ToLower().Contains("chauffeur") ? Convert.ToDateTime(dr["from_date"].ToString()) : Convert.ToDateTime(dr["to_date"].ToString()),
                                type      = dr["type"].ToString(),

                                complaint = fleetServeDetails.complaint,
                                end_km    = fleetServeDetails.end_km,
                                note      = fleetServeDetails.note,
                                plate     = fleetServeDetails.plate,
                                sar       = fleetServeDetails.sar,
                            };

                            break;
                            //}
                        }
                    }
                }
            }

            //var request = new TemplateRequest();
            ////request.registration_ids = listReturn.ToArray();
            //request.data = new TemplateRequest.Data(listReturn);

            //string json = new JavaScriptSerializer().Serialize(request);

            return(objReturn);
        }
Esempio n. 4
0
        public FleetRequestAction FleetRequestApprove(string service_ref, string random, string randomize)
        {
            var fleetRequest   = new FleetRequest();
            var requestDetails = fleetRequest.GetRequestsDetails(service_ref);

            if (requestDetails.service_ref != null)
            {
                if (requestDetails.random == random && requestDetails.randomize == randomize)
                {
                    //var request = WebRequest.Create("http://ez.kaec.net/seat/main/fleet_link?random=" + random + "&randomize=" + randomize + "&action=15A329C8") as HttpWebRequest;
                    var request  = WebRequest.Create("http://mydirectory.kaec.net/eec/main/fleet_verify?random=" + random + "&randomize=" + randomize) as HttpWebRequest;
                    var response = request.GetResponse() as HttpWebResponse;

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        //try {
                        //    using (var con = new MySqlConnection(ConnectionHelper.ServicesConnection()))
                        //    {

                        //        con.Open();
                        //        var cmd = new MySqlCommand();
                        //        cmd = new MySqlCommand("UPDATE fleet_request " +
                        //                                        "SET method='EEC Mobility' WHERE service_ref=@service_ref", con);
                        //        cmd.Parameters.AddWithValue("@service_ref", service_ref);
                        //        var result = cmd.ExecuteNonQuery();
                        //        if (result > 0)
                        //        {

                        return(new FleetRequestAction
                        {
                            status = "success",
                            remarks = "approved by line manager",
                        });
                        //        }

                        //        else
                        //        {
                        //            return new FleetRequestAction
                        //            {
                        //                status = "failed",
                        //                remarks = "api error has occured",
                        //            };
                        //        }
                        //    }
                    }

                    //    catch
                    //    {
                    //        return new FleetRequestAction
                    //        {
                    //            status = "failed",
                    //            remarks = "api error has occured",
                    //        };
                    //    }
                    //}

                    else
                    {
                        return(new FleetRequestAction
                        {
                            status = "failed",
                            remarks = "link error has occured",
                        });
                    }
                }

                else
                {
                    return(new FleetRequestAction
                    {
                        status = "failed",
                        remarks = "action has already been taken",
                    });
                }
            }

            else
            {
                return(new FleetRequestAction
                {
                    status = "failed",
                    remarks = "record not found",
                });
            }
        }