Ejemplo n.º 1
0
        public LocationModel Insert(LocationModel model)
        {
            try
            {
                string query = @"INSERT INTO Location(
                                 LocCode
                                ,LocName
                                ,LocLatitude
                                ,LocLongitude
                                ,LocRemarks)
                                output INSERTED.LocId
                                VALUES(
                                 @LocCode
                                ,@LocName
                                ,@LocLatitude
                                ,@LocLongitude
                                ,@LocRemarks)
                                ";

                fun.OpenConnection();
                if (fun.getConnection().State == System.Data.ConnectionState.Open)
                {
                    List <SqlParameter> param = new List <SqlParameter>();
                    param.Add(new SqlParameter("@LocCode", model.LocCode));
                    param.Add(new SqlParameter("@LocName", model.LocName));
                    param.Add(new SqlParameter("@LocLatitude", model.LocLatitude));
                    param.Add(new SqlParameter("@LocLongitude", model.LocLongitude));
                    param.Add(new SqlParameter("@LocRemarks", model.LocRemarks));

                    model.LocId = fun.ExecuteQueryWithParameters(query, param, "Yes");
                }
                else
                {
                    throw new Exception("Please check Network connection");
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public LocationModel GetLocation(int locId)
        {
            try
            {
                LocationModel model = new LocationModel();
                string        query = String.Format(@"SELECT [LocId]
                                  ,[LocCode]
                                  ,[LocName]
                                  ,[LocLatitude]
                                  ,[LocLongitude]
                                  ,[LocRemarks]
                              FROM [Location] WHERE [LocId] = {0}", locId);

                fun.OpenConnection();
                if (fun.getConnection().State == ConnectionState.Open)
                {
                    DataSet ds = fun.fillComboDataset(query);
                    if (ds.Tables.Count > 0)
                    {
                        foreach (DataRow item in ds.Tables[0].Rows)
                        {
                            model.LocCode      = item["LocCode"].ToString();
                            model.LocId        = locId;
                            model.LocLatitude  = item["LocLatitude"].ToString();
                            model.LocLongitude = item["LocLongitude"].ToString();
                            model.LocName      = item["LocName"].ToString();
                            model.LocRemarks   = item["LocRemarks"].ToString();
                        }
                    }
                }
                else
                {
                    throw new Exception("Please check network connection");
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public LocationModel Update(LocationModel model)
        {
            try
            {
                string query = @"UPDATE Location SET
                                 LocCode = @LocCode
                                ,LocName = @LocName
                                ,LocLatitude = @LocLatitude
                                ,LocLongitude = @LocLongitude
                                ,LocRemarks = @LocRemarks
                                WHERE LocId = @LocId
                                ";

                fun.OpenConnection();
                if (fun.getConnection().State == System.Data.ConnectionState.Open)
                {
                    List <SqlParameter> param = new List <SqlParameter>();
                    param.Add(new SqlParameter("@LocId", model.LocId));
                    param.Add(new SqlParameter("@LocCode", model.LocCode));
                    param.Add(new SqlParameter("@LocName", model.LocName));
                    param.Add(new SqlParameter("@LocLatitude", model.LocLatitude));
                    param.Add(new SqlParameter("@LocLongitude", model.LocLongitude));
                    param.Add(new SqlParameter("@LocRemarks", model.LocRemarks));

                    fun.ExecuteQueryWithParameters(query, param);
                }
                else
                {
                    throw new Exception("Please check Network connection");
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
 public LocationModel GetLocationDetails(int LocId)
 {
     try
     {
         string        query = String.Format(@"select LocId,LocCode, LocName, LocLatitude, LocLongitude,LocRemarks 
         from Location where LocId = {0}", LocId);
         DataSet       ds    = new DataSet();
         LocationModel model = new LocationModel();
         fun.OpenConnection();
         if (fun.getConnection().State == ConnectionState.Open)
         {
             ds = fun.fillComboDataset(query);
         }
         else
         {
             ds = temp.fillComboDataset(query);
         }
         if (ds.Tables.Count > 0)
         {
             foreach (DataRow item in ds.Tables[0].Rows)
             {
                 model.LocCode      = item["LocCode"].ToString();
                 model.LocId        = Convert.ToInt32(item["LocId"].ToString());
                 model.LocLatitude  = item["LocLatitude"].ToString();
                 model.LocLongitude = item["LocLongitude"].ToString();
                 model.LocName      = item["LocName"].ToString();
                 model.LocRemarks   = item["LocRemarks"].ToString();
             }
         }
         return(model);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }