Exemplo n.º 1
0
        /// <summary>
        /// addres get from database
        /// </summary>
        /// <param name="locationId"></param>
        /// <returns></returns>
        public LocationModel GetAddressfromDataBase(string locationId, Ctx ctx)
        {
            LocationModel obj = new LocationModel();
            string        sql = "";

            // Check applied by mohit - asked by mukesh sir - to check if login langauge is base language - then pick non translated data.
            if (Env.IsBaseLanguage(ctx, ""))
            {
                sql = "SELECT L.ADDRESS1,L.ADDRESS2,L.ADDRESS3,L.ADDRESS4,L.CITY,L.REGIONNAME ,L.POSTAL,L.POSTAL_ADD,CN.NAME AS COUNTRY,L.AD_CLIENT_ID,L.AD_ORG_ID,L.C_CITY_ID," +
                      " L.C_COUNTRY_ID,L.C_LOCATION_ID,L.C_REGION_ID FROM C_LOCATION L" +
                      " LEFT JOIN C_COUNTRY CN ON CN.C_COUNTRY_ID=L.C_COUNTRY_ID WHERE L.IsActive='Y'";
            }
            else
            {
                // Check applied by mohit - Picked data from translation tab - if base language
                sql = "SELECT L.ADDRESS1,L.ADDRESS2,L.ADDRESS3,L.ADDRESS4,L.CITY,L.REGIONNAME ,L.POSTAL,L.POSTAL_ADD,CNTRL.NAME AS COUNTRY,L.AD_CLIENT_ID,L.AD_ORG_ID,L.C_CITY_ID," +
                      " L.C_COUNTRY_ID,L.C_LOCATION_ID,L.C_REGION_ID FROM C_LOCATION L" +
                      " LEFT JOIN C_COUNTRY CN ON CN.C_COUNTRY_ID=L.C_COUNTRY_ID INNER JOIN C_Country_trl CNTRL ON (CN.C_COUNTRY_ID  =CNTRL.C_COUNTRY_ID)" +
                      " WHERE L.IsActive='Y' AND CNTRL.AD_Language='" + ctx.GetAD_Language() + "' ";
            }

            sql += " AND L.c_location_id=" + locationId;

            var ds = new DataSet();

            try
            {
                ds = DB.ExecuteDataset(sql);

                if (ds != null)
                {
                    //DataRow[] dr = ds.Tables[0].Select("c_location_id=" + locationId);
                    DataRowCollection dr = ds.Tables[0].Rows;
                    //if contain saved records
                    if (dr.Count > 0)
                    {
                        if (dr[0].ItemArray.Length > 0)
                        {
                            obj.Address1 = Convert.ToString(dr[0]["Address1"] == DBNull.Value ? "" : dr[0]["Address1"]);
                            obj.Address2 = Convert.ToString(dr[0]["Address2"] == DBNull.Value ? "" : dr[0]["Address2"]);
                            obj.Address3 = Convert.ToString(dr[0]["Address3"] == DBNull.Value ? "" : dr[0]["Address3"]);
                            obj.Address4 = Convert.ToString(dr[0]["Address4"] == DBNull.Value ? "" : dr[0]["Address4"]);

                            obj.C_City_ID    = Convert.ToInt32(dr[0]["C_City_ID"] == DBNull.Value ? 0 : dr[0]["C_City_ID"]);
                            obj.C_Country_ID = Convert.ToInt32(dr[0]["C_Country_ID"] == DBNull.Value ? 0 : dr[0]["C_Country_ID"]);
                            obj.C_Region_ID  = Convert.ToInt32(dr[0]["C_Region_ID"] == DBNull.Value ? 0 : dr[0]["C_Region_ID"]);

                            obj.City       = Convert.ToString(dr[0]["City"] == DBNull.Value ? "" : dr[0]["City"]);
                            obj.RegionName = Convert.ToString(dr[0]["RegionName"] == DBNull.Value ? "" : dr[0]["RegionName"]);
                            obj.Country    = Convert.ToString(dr[0]["Country"] == DBNull.Value ? "" : dr[0]["Country"]);

                            obj.ZipCode = Convert.ToString(dr[0]["POSTAL"] == DBNull.Value ? "" : dr[0]["POSTAL"]);
                        }
                    }

                    ////Auto fill search control
                    //obj.Addresslist = new List<SearchAddress>();
                    //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    //{
                    //    SearchAddress searchObj = new SearchAddress();
                    //    if (i == 0)
                    //    {
                    //        obj.Addresslist.Add(searchObj);
                    //        searchObj = new SearchAddress();
                    //    }
                    //    searchObj.Name = Convert.ToString(ds.Tables[0].Rows[i]["Country"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Country"]) +
                    //        "," + Convert.ToString(ds.Tables[0].Rows[i]["Address1"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address1"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["Address2"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address2"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["Address3"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address3"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["Address4"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address4"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["City"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["City"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["RegionName"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["RegionName"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["POSTAL"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["POSTAL"]);

                    //    searchObj.ID = Convert.ToInt32(ds.Tables[0].Rows[i]["c_location_id"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["c_location_id"]);
                    //    searchObj.CityId = Convert.ToInt32(ds.Tables[0].Rows[i]["C_City_ID"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["C_City_ID"]);
                    //    searchObj.StateId = Convert.ToInt32(ds.Tables[0].Rows[i]["C_Region_ID"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["C_Region_ID"]);
                    //    searchObj.CountryId = Convert.ToInt32(ds.Tables[0].Rows[i]["C_Country_ID"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["C_Country_ID"]);

                    //    obj.Addresslist.Add(searchObj);
                    //}
                }
            }
            catch (Exception ev)
            {
            }
            ds = null;
            return(obj);
        }
Exemplo n.º 2
0
        /// <summary>
        /// addres get from database
        /// </summary>
        /// <param name="locationId"></param>
        /// <returns></returns>
        public LocationModel GetAddressfromDataBase(string locationId)
        {
            LocationModel obj = new LocationModel();
            //string sql = "select l.ADDRESS1,l.ADDRESS2,l.ADDRESS3,l.ADDRESS4,l.CITY,l.REGIONNAME ,l.POSTAL,l.POSTAL_ADD,cn.Name as Country,l.AD_CLIENT_ID,l.AD_ORG_ID,l.C_CITY_ID," +
            //             " l.C_COUNTRY_ID,l.C_LOCATION_ID,l.C_REGION_IDfrom c_location l--left join c_city ct on ct.c_city_id=l.c_city_id--left join c_region s on s.c_region_id=l.C_REGION_ID" +
            //             " left join c_country cn on cn.C_COUNTRY_ID=l.C_COUNTRY_ID where l.ISACTIVE='Y'";

            string sql = "SELECT L.ADDRESS1,L.ADDRESS2,L.ADDRESS3,L.ADDRESS4,L.CITY,L.REGIONNAME ,L.POSTAL,L.POSTAL_ADD,CN.NAME AS COUNTRY,L.AD_CLIENT_ID,L.AD_ORG_ID,L.C_CITY_ID," +
                         " L.C_COUNTRY_ID,L.C_LOCATION_ID,L.C_REGION_ID FROM C_LOCATION L" +
                         " LEFT JOIN C_COUNTRY CN ON CN.C_COUNTRY_ID=L.C_COUNTRY_ID ";

            var ds = new DataSet();

            try
            {
                ds = DB.ExecuteDataset(sql);

                if (ds != null)
                {
                    DataRow[] dr = ds.Tables[0].Select("c_location_id=" + locationId);
                    //if contain saved records
                    if (dr.Length > 0)
                    {
                        if (dr[0].ItemArray.Length > 0)
                        {
                            obj.Address1 = Convert.ToString(dr[0]["Address1"] == DBNull.Value ? "" : dr[0]["Address1"]);
                            obj.Address2 = Convert.ToString(dr[0]["Address2"] == DBNull.Value ? "" : dr[0]["Address2"]);
                            obj.Address3 = Convert.ToString(dr[0]["Address3"] == DBNull.Value ? "" : dr[0]["Address3"]);
                            obj.Address4 = Convert.ToString(dr[0]["Address4"] == DBNull.Value ? "" : dr[0]["Address4"]);

                            obj.C_City_ID    = Convert.ToInt32(dr[0]["C_City_ID"] == DBNull.Value ? 0 : dr[0]["C_City_ID"]);
                            obj.C_Country_ID = Convert.ToInt32(dr[0]["C_Country_ID"] == DBNull.Value ? 0 : dr[0]["C_Country_ID"]);
                            obj.C_Region_ID  = Convert.ToInt32(dr[0]["C_Region_ID"] == DBNull.Value ? 0 : dr[0]["C_Region_ID"]);

                            obj.City       = Convert.ToString(dr[0]["City"] == DBNull.Value ? "" : dr[0]["City"]);
                            obj.RegionName = Convert.ToString(dr[0]["RegionName"] == DBNull.Value ? "" : dr[0]["RegionName"]);
                            obj.Country    = Convert.ToString(dr[0]["Country"] == DBNull.Value ? "" : dr[0]["Country"]);

                            obj.ZipCode = Convert.ToString(dr[0]["POSTAL"] == DBNull.Value ? "" : dr[0]["POSTAL"]);
                        }
                    }

                    ////Auto fill search control
                    //obj.Addresslist = new List<SearchAddress>();
                    //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    //{
                    //    SearchAddress searchObj = new SearchAddress();
                    //    if (i == 0)
                    //    {
                    //        obj.Addresslist.Add(searchObj);
                    //        searchObj = new SearchAddress();
                    //    }
                    //    searchObj.Name = Convert.ToString(ds.Tables[0].Rows[i]["Country"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Country"]) +
                    //        "," + Convert.ToString(ds.Tables[0].Rows[i]["Address1"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address1"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["Address2"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address2"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["Address3"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address3"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["Address4"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["Address4"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["City"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["City"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["RegionName"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["RegionName"])
                    //        + "," + Convert.ToString(ds.Tables[0].Rows[i]["POSTAL"] == DBNull.Value ? "" : ds.Tables[0].Rows[i]["POSTAL"]);

                    //    searchObj.ID = Convert.ToInt32(ds.Tables[0].Rows[i]["c_location_id"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["c_location_id"]);
                    //    searchObj.CityId = Convert.ToInt32(ds.Tables[0].Rows[i]["C_City_ID"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["C_City_ID"]);
                    //    searchObj.StateId = Convert.ToInt32(ds.Tables[0].Rows[i]["C_Region_ID"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["C_Region_ID"]);
                    //    searchObj.CountryId = Convert.ToInt32(ds.Tables[0].Rows[i]["C_Country_ID"] == DBNull.Value ? 0 : ds.Tables[0].Rows[i]["C_Country_ID"]);

                    //    obj.Addresslist.Add(searchObj);
                    //}
                }
            }
            catch (Exception ev)
            {
            }
            ds = null;
            return(obj);
        }