예제 #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            double latitude  = 0;
            double longitude = 0;

            if (txtLongitude.Text != "")
            {
                latitude = double.Parse(txtLongitude.Text.Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture);
            }
            if (txtLongitude.Text != "")
            {
                longitude = double.Parse(txtLongitude.Text.Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture);
            }

            DataTable dtCities = objAdmin.GetCitiesList(Convert.ToInt32(ddlCity.SelectedValue));

            if (dtCities.Rows.Count > 0)
            {
                try
                {
                    int cnt = 0;
                    for (int i = 0; i < dtCities.Rows.Count; i++)
                    {
                        //double dist = CalculateDistance(dtCities.Rows[i]["CityName"].ToString() + ", Germany", txt_City.Text + ", Germany");
                        double dist = CalculateDistance(dtCities.Rows[i]["lat"].ToString().Replace(",", ".") + "," + dtCities.Rows[i]["long"].ToString().Replace(",", "."), txtLatitude.Text.Replace(',', '.') + "," + txtLongitude.Text.Replace(',', '.'));

                        if (dist > 0)
                        {
                            int opt = objAdmin.InsertCityDistance(Convert.ToInt32(dtCities.Rows[i]["CityId"]), Convert.ToInt32(ddlCity.SelectedValue), Convert.ToInt32(dist));
                            if (opt > 0)
                            {
                                cnt++;
                            }
                        }
                    }

                    if (cnt > 0)
                    {
                        string popupScript = "alert('" + cnt.ToString() + " Saved!');";//City deleted successfully.
                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                    }
                }
                catch (Exception ex) { }
            }
        }
        catch { }
    }
예제 #2
0
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        try
        {
            string imageName = "";
            int    CityId = 0, res = 0;
            string action   = "Insert";
            string FromCity = string.Empty;
            if (hdn_CityId.Value != "")
            {
                CityId = Convert.ToInt32(hdn_CityId.Value);
                action = "Update";
                // ddlCity.SelectedItem.Value = hdn_CityId.Value;
            }

            if (txt_City.Text.Trim() != null)
            {
                //FromCity = txt_City.Text.Trim() +",Germany";
                double latitude  = 0;
                double longitude = 0;

                if (hdnLatitude.Value != "")
                {
                    latitude = double.Parse(hdnLatitude.Value, System.Globalization.CultureInfo.InvariantCulture);
                }
                if (hdnLongitude.Value != "")
                {
                    longitude = double.Parse(hdnLongitude.Value, System.Globalization.CultureInfo.InvariantCulture);
                }

                if (action == "Update")
                {
                    if (fuCityImage.HasFile)
                    {
                        imageName = fuCityImage.PostedFile.FileName;
                        fuCityImage.SaveAs(Server.MapPath("../CityImages/" + imageName));
                    }
                    else
                    {
                        imageName = hdnImageName.Value;
                    }
                }
                else
                {
                    if (fuCityImage.HasFile)
                    {
                        imageName = fuCityImage.PostedFile.FileName;
                        fuCityImage.SaveAs(Server.MapPath("../CityImages/" + imageName));
                    }
                }
                if (latitude > 0 && longitude > 0)
                {
                    //InsertUpdateParicipatingCities(int CityId, string CityName, string CityNameGerman, bool isPartcipating, double lat, double longt)
                    res = objAdmin.InsertUpdateParicipatingCities(Convert.ToInt32(CityId), txt_City.Text.Trim(), txt_CityGer.Text.Trim(), imageName, chkIsParticipating.Checked, latitude, longitude, txtMapText.Text);

                    if (res > 0)
                    {
                        if (CityId == 0)
                        {
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgAddCity") + "');";//City added successfully!
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                        }
                        else
                        {
                            string popupScript = "alert('" + (string)GetLocalResourceObject("MsgUpdateCity") + "');";//City details updated successfully!
                            ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                        }

                        if (action == "Insert")
                        {
                            DataTable dtCities = objAppAdmin.GetCitiesList(res);

                            if (dtCities.Rows.Count > 0)
                            {
                                try
                                {
                                    for (int i = 0; i < dtCities.Rows.Count; i++)
                                    {
                                        //double dist = CalculateDistance(dtCities.Rows[i]["CityName"].ToString() + ", Germany", txt_City.Text + ", Germany");
                                        double dist = CalculateDistance(dtCities.Rows[i]["lat"].ToString().Replace(",", ".") + "," + dtCities.Rows[i]["long"].ToString().Replace(",", "."), hdnLatitude.Value.ToString() + "," + hdnLongitude.Value.ToString());

                                        if (dist > 0)
                                        {
                                            int opt = objAppAdmin.InsertCityDistance(Convert.ToInt32(dtCities.Rows[i]["CityId"]), res, Convert.ToInt32(dist));
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                            }
                        }
                        //grd_CityList.DataBind();
                        _Bind();
                        hdn_CityId.Value     = "";
                        pnl_CityList.Visible = true;
                        pnl_AddCity.Visible  = false;
                        imgImage.Visible     = false;
                        imgImage.ImageUrl    = "";
                        txtSearchBox.Text    = "";
                        _Bind();
                    }
                    else
                    {
                        string popupScript = "alert('" + (string)GetLocalResourceObject("MsgAlreadyCity") + "');";//City already exits!
                        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript + "GetLocations();", true);
                    }
                }
                else
                {
                    string popupScript = "alert('" + (string)GetLocalResourceObject("MsgInvalidCity") + "');";//Invalid city name!
                    ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, true);
                }
            }
        }
        catch { }
    }