public int Incident_Insert(IncidentDetails incident)
        {
            using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("EyeD_Incident_Insert", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@userID", SqlDbType.UniqueIdentifier).Value = Guid.Parse(incident.User_ID);
                cmd.Parameters.Add("@subject", SqlDbType.VarChar).Value = incident.Subject;
                cmd.Parameters.Add("@description", SqlDbType.VarChar).Value = incident.Description;
                cmd.Parameters.Add("@incident_datetime", SqlDbType.DateTime).Value = incident.Incident_datetime;
                cmd.Parameters.Add("@insert_status", SqlDbType.Bit).Value = incident.Insert_Status;
                if (incident.Address_ID == -1)
                    cmd.Parameters.Add("@addr_ID", SqlDbType.Int).Value = null;
                else
                    cmd.Parameters.Add("@addr_ID", SqlDbType.Int).Value = incident.Address_ID;
                cn.Open();

                DataTable dt = new DataTable();
                dt.Load(ExecuteReader(cmd));

                int incidentID = int.Parse(dt.Rows[0].ItemArray[0].ToString());

                foreach (IncidentTypeDetails iType in incident.Incident_types)
                {
                    cmd = new SqlCommand("EyeD_lnk_Incident_Type_Insert", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@incidentID", SqlDbType.Int).Value = incidentID;
                    cmd.Parameters.Add("@typeID", SqlDbType.Int).Value = iType.Incident_Type_ID;

                    ExecuteNonQuery(cmd);
                }

                return incidentID;
            }
        }
        public void Incident_Update(IncidentDetails incident)
        {
            using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("EyeD_Incident_Update", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@incidentID", SqlDbType.Int).Value = incident.Incident_ID;
                cmd.Parameters.Add("@subject", SqlDbType.VarChar).Value = incident.Subject;
                cmd.Parameters.Add("@description", SqlDbType.VarChar).Value = incident.Description;
                cmd.Parameters.Add("@incident_datetime", SqlDbType.DateTime).Value = incident.Incident_datetime;
                cmd.Parameters.Add("@people_involved", SqlDbType.Int).Value = incident.People_Involved;
                cmd.Parameters.Add("@other_incident_type", SqlDbType.VarChar).Value = incident.Other_Incident_Type;
                cmd.Parameters.Add("@delete_status", SqlDbType.Bit).Value = incident.Delete_Status;
                cmd.Parameters.Add("@addr_ID", SqlDbType.Int).Value = incident.Address_ID;
                cn.Open();

                ExecuteNonQuery(cmd);

                cmd = new SqlCommand("EyeD_lnk_Incident_Type_Delete", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@incidentID", SqlDbType.Int).Value = incident.Incident_ID;
                ExecuteNonQuery(cmd);

                foreach (IncidentTypeDetails iType in incident.Incident_types)
                {
                    cmd = new SqlCommand("EyeD_lnk_Incident_Type_Insert", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@incidentID", SqlDbType.Int).Value = incident.Incident_ID;
                    cmd.Parameters.Add("@typeID", SqlDbType.Int).Value = iType.Incident_Type_ID;
                    ExecuteNonQuery(cmd);
                }

                cmd = new SqlCommand("EyeD_Incident_People_Delete", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@incidentID", SqlDbType.Int).Value = incident.Incident_ID;
                ExecuteNonQuery(cmd);

                foreach (IncidentPeopleDetails iPeople in incident.Incident_people)
                {
                    cmd = new SqlCommand("EyeD_Incident_People_Insert", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@incidentID", SqlDbType.Int).Value = incident.Incident_ID;
                    cmd.Parameters.Add("@gender", SqlDbType.VarChar).Value = iPeople.Gender;
                    cmd.Parameters.Add("@age_group", SqlDbType.VarChar).Value = iPeople.Age_Group;
                    cmd.Parameters.Add("@description", SqlDbType.VarChar).Value = iPeople.Description;
                    ExecuteNonQuery(cmd);
                }
            }
        }
        private void PopulateMap(IncidentDetails incidentDetails, AdddressDetails incidentAddr, StoreDetails loggedinUserAddress)
        {
            IncidentMap.MapType = MapType.Roadmap;
            IncidentMap.EnterpriseKey = Utility.GetGoogleAPIKey();
            IncidentMap.Latitude = incidentAddr.Latitude;
            IncidentMap.Longitude = incidentAddr.Longitude;
            IncidentMap.Zoom = Utility.GetGoogleZoomLevel(incidentAddr.Latitude, incidentAddr.Longitude, loggedinUserAddress.Store_Address.Latitude, loggedinUserAddress.Store_Address.Longitude);

            MarkerImage incidentMarkerIamge = new MarkerImage();
            incidentMarkerIamge.Url = "http://www.eyedentify.co.nz/Images/Map/map_Incident_Icon.jpg";

            MarkerImage homeMarkerIamge = new MarkerImage();
            homeMarkerIamge.Url = "http://www.eyedentify.co.nz/Images/Map/map_Home_Icon.png";

            Marker incidentMarker = new Marker();
            incidentMarker.Address = incidentAddr.Latitude + " " + incidentAddr.Longitude;
            incidentMarker.Info = incidentDetails.Description;
            incidentMarker.Icon = incidentMarkerIamge;
            IncidentMap.Markers.Add(incidentMarker);

            Marker yourAddressMarker = new Marker();
            yourAddressMarker.Address = loggedinUserAddress.Store_Address.Latitude + " " + loggedinUserAddress.Store_Address.Longitude;
            yourAddressMarker.Info = "Your Store";
            yourAddressMarker.Icon = homeMarkerIamge;
            IncidentMap.Markers.Add(yourAddressMarker);
        }
 private void CheckIncidentStatus(IncidentDetails id)
 {
     if (id.Delete_Status || !id.Insert_Status)
         Response.Redirect("MemberHome.aspx");
 }
        private void PopulateLabels(IncidentDetails id)
        {
            LocationLabel.Text = "Bling, Newmarket, Auckland";
            TimeLabel.Text = id.Incident_datetime.ToShortDateString() + " " + id.Incident_datetime.ToShortTimeString();

            DescriptionLabel.Text = id.Description;
            if (id.People_Involved == 0)
            {
                PeopleInvolvedLabel.Text = "No details of involved offenders";
            }
            else
            {
                PeopleInvolvedLabel.Text = id.People_Involved + "";
                PeopleBindData(id.Incident_people);
            }

            List<IncidentTypeDetails> itds = sip.Incident_Get_Types(id.Incident_ID);
            string incidentTypeString = string.Empty;
            if (itds.Count == 0)
            {
                incidentTypeString = "type of incident not defined";
            }
            else
            {
                foreach (IncidentTypeDetails itd in itds)
                {
                    incidentTypeString += itd.Incident_Type_Name + ", ";
                }
            }
            TypeLabel.Text = incidentTypeString.Substring(0, incidentTypeString.Length - 2);
        }
        private void PopulateLabels(IncidentDetails id, string userID, AdddressDetails incidentAddr)
        {
            if (!id.Store_Name.Equals(string.Empty))
                LocationLabel.Text = id.Store_Name + ", ";
            else
                LocationLabel.Text = string.Empty;
            LocationLabel.Text = LocationLabel.Text + incidentAddr.Suburb + ", " + incidentAddr.City + ", " + incidentAddr.Country;

            TimeLabel.Text = id.Incident_datetime.ToShortDateString() + " " + id.Incident_datetime.ToShortTimeString();

            DescriptionLabel.Text = id.Description;
            if (id.People_Involved == 0)
            {
                PeopleInvolvedLabel.Text = "No details of involved offenders";
            }
            else
            {
                PeopleInvolvedLabel.Text = id.People_Involved + "";
                PeopleBindData(id.Incident_people);
            }

            List<IncidentTypeDetails> itds = sip.Incident_Get_Types(id.Incident_ID);
            string incidentTypeString = string.Empty;
            if (itds.Count == 0)
            {
                incidentTypeString = "type of incident not defined";
            }
            else
            {
                foreach (IncidentTypeDetails itd in itds)
                {
                    incidentTypeString += itd.Incident_Type_Name + ", ";
                }
            }
            TypeLabel.Text = incidentTypeString.Substring(0, incidentTypeString.Length - 2);
        }
 private static IncidentDetails GetIncidentDetails(IDataReader reader)
 {
     IncidentDetails incidentDetails = new IncidentDetails(
         int.Parse(reader["Incident_ID"].ToString()),
         reader["User_ID"].ToString(),
         reader["Subject"].ToString(),
         reader["Description"].ToString(),
        (DateTime)reader["Incident_DateTime"],
          new List<IncidentTypeDetails> { },
           new List<IncidentPeopleDetails> { },
          int.Parse(reader["People_Involved"].ToString()),
          reader["Other_Incident_Type"].ToString(),
         (bool)reader["Insert_Status"],
         (bool)reader["Delete_Status"],
          reader["Delete_Reason"].ToString(),
          int.Parse(reader["Address_ID"].ToString()),
          reader["Store_Name"].ToString()
         );
     return incidentDetails;
 }
 public static IncidentDetails GetIncidentDetailsFromReader(IDataReader reader)
 {
     IncidentDetails incidentDetailsCol = new IncidentDetails();
     while (reader.Read())
         incidentDetailsCol = GetIncidentDetails(reader);
     return incidentDetailsCol;
 }
        private void PopulatePageDetails(IncidentDetails id)
        {
            IncidentDateTime.Text = id.Incident_datetime.Day + "-" + id.Incident_datetime.Month + "-" + id.Incident_datetime.Year + " " + id.Incident_datetime.ToShortTimeString().Replace(".", "");

            foreach (IncidentTypeDetails itd in id.Incident_types)
            {
                IncidentTypeListBox.Items.FindByText(itd.Incident_Type_Name).Selected = true;
            }

            if (IncidentTypeListBox.SelectedIndex > 0)
            {
                if (IncidentTypeListBox.SelectedItem.Text == "Other")
                {
                    OtherIncidentTypePanel.Visible = true;
                    OtherIncidentyTypeBox.Text = id.Other_Incident_Type;
                }
            }

            DescriptionBox.Text = id.Description;

            NoPeopleDropDown.Items.FindByValue(id.People_Involved + "").Selected = true;
            if (id.People_Involved > 0)
            {
                PeopleBindData(id.Incident_people);
            }

            DataTable dt = sip.Incident_Get_Main_Incident(id.Incident_ID);

            if (dt.Rows.Count > 0)
            {
                OtherIncidentsListBox.SelectedValue = dt.Rows[0]["Main_Incident_ID"].ToString();

                string otherIncident = OtherIncidentsListBox.SelectedItem.Text;
                LinkOtherIncidentLinkButton.Text = "Click here to link to other incident. (Currently linked to \"" + otherIncident + "\" incident)";
            }
        }
        private IncidentDetails PopulateIncidentDetails(int incidentID)
        {
            MembershipUser user = Membership.GetUser(User.Identity.Name);
            string usedID = user.ProviderUserKey.ToString();
            string datetime = IncidentDateTime.Text;

            string day = datetime.Split('-')[0];
            string month = datetime.Split('-')[1];
            string yearTime = datetime.Split('-')[2];
            datetime = day + "/" + month + "/" + yearTime;
            DateTime date = DateTime.Parse(datetime);

            int[] selectedtypes = IncidentTypeListBox.GetSelectedIndices();
            List<IncidentTypeDetails> types = new List<IncidentTypeDetails> { };

            foreach (int selectedIndex in selectedtypes)
            {
                types.Add(new IncidentTypeDetails(int.Parse(IncidentTypeListBox.Items[selectedIndex].Value), IncidentTypeListBox.Items[selectedIndex].Text));
            }

            List<IncidentPeopleDetails> people = GetPeopleDetails(incidentID);

            string otherIT = "";
            if (IncidentTypeListBox.SelectedIndex > -1)
            {
                if (IncidentTypeListBox.SelectedItem.Text == "Other")
                    otherIT = OtherIncidentyTypeBox.Text.Trim();
                else
                    otherIT = string.Empty;
            }

            string description = DescriptionBox.Text.ToString().Trim();

            string storeName = LocationLabel.Text.Substring(0, LocationLabel.Text.IndexOf(','));

            int NoOfPeopleInvolved = 0;

            if (NoPeopleDropDown.SelectedIndex > 0)
                NoOfPeopleInvolved = int.Parse(NoPeopleDropDown.SelectedValue);

            IncidentDetails id = new IncidentDetails(incidentID, usedID, string.Empty, description, date, types, people,
                NoOfPeopleInvolved, otherIT, false, false, string.Empty, int.Parse(AddressIDLabel.Text), storeName);
            return id;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MembershipUser user = Membership.GetUser(User.Identity.Name);
                string userID = user.ProviderUserKey.ToString();

                StoreDetails loggedInUserStore = ssp.Store_Get_User_Store_Info(userID);

                PopulateLocationLabel(loggedInUserStore);
                PopulateIncidentTypeBox();
                PopulateOtherIncidentBox();

                int incidentID = Request.QueryString["iID"] == null ? -1 : int.Parse(Request.QueryString["iID"].ToString());

                if (loggedInUserStore.Store_ID == 0)
                {
                    Response.Redirect("ErrorPage.aspx?Error=MemberNoStore");
                }
                else
                {

                    if (incidentID == -1)
                    {
                        IncidentDetails id = new IncidentDetails(-1, userID, string.Empty, string.Empty, DateTime.Now, new List<IncidentTypeDetails> { },
                            new List<IncidentPeopleDetails> { }, 0, string.Empty, false, false, string.Empty, -1, string.Empty);
                        IncidentID.Text = sip.Incident_Insert(id).ToString();
                    }
                    else
                    {
                        IncidentDetails id = sip.Incident_Get_Details(incidentID);

                        if (userID != id.User_ID || id.Insert_Status == true)
                            Response.Redirect("MemberHome.aspx");
                        else
                        {
                            IncidentID.Text = incidentID + "";
                            BindImageGridData();

                            PopulatePageDetails(id);
                        }
                    }
                }
            }
        }