public RigModel GetRig(int RigId)
        {
            RigModel model = new RigModel();

            try
            {
                string query = String.Format(@"SELECT [RigId]
                                  ,[RigCode]
                                  ,[RigName]
                                  ,[RigManufacturer]
                                  ,[RigProject]
                                  ,[LocId]
                                  ,[RigTypeId]
                                  ,[RigModelNo]
                                  ,[RigRemarks]
                                  ,[RigDeployed]
                                  ,[RigLocation]
                                  ,[RigTypeName]
                              FROM [Rig] WHERE [RigId] = {0}", RigId);
                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.LocId   = Convert.ToInt32(item["LocId"].ToString());
                            model.RigCode = item["RigCode"].ToString();
                            if (item["RigDeployed"].ToString() == "")
                            {
                                model.RigDeployed = null;
                            }
                            else
                            {
                                model.RigDeployed = Convert.ToDateTime(item["RigDeployed"].ToString());
                            }
                            model.RigId           = RigId;
                            model.RigManufacturer = item["RigManufacturer"].ToString();
                            model.RigModelNo      = item["RigModelNo"].ToString();
                            model.RigName         = item["RigName"].ToString();
                            model.RigProject      = item["RigProject"].ToString();
                            model.RigRemarks      = item["RigRemarks"].ToString();
                            model.RigTypeId       = Convert.ToInt32(item["RigTypeId"].ToString());
                            model.RigLocation     = item["RigLocation"].ToString();
                            model.RigTypeName     = item["RigTypeName"].ToString();
                        }
                    }
                }
                else
                {
                    throw new Exception("Please check network connection");
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public RigModel Insert(RigModel model)
 {
     try
     {
         string query = @"INSERT INTO Rig(
                          RigCode
                         ,RigName
                         ,RigManufacturer
                         ,RigProject
                         ,LocId
                         ,RigTypeId
                         ,RigModelNo
                         ,RigRemarks
                         ,RigDeployed
                         ,RigLocation
                         ,RigTypeName)
                         output INSERTED.RigId
                         VALUES(
                          @RigCode
                         ,@RigName
                         ,@RigManufacturer
                         ,@RigProject
                         ,@LocId
                         ,@RigTypeId
                         ,@RigModelNo
                         ,@RigRemarks
                         ,@RigDeployed
                         ,@RigLocation
                         ,@RigTypeName)
                         ";
         List <SqlParameter> param = new List <SqlParameter>();
         param.Add(new SqlParameter("@RigCode", model.RigCode));
         param.Add(new SqlParameter("@RigName", model.RigName));
         param.Add(new SqlParameter("@RigManufacturer", model.RigManufacturer));
         param.Add(new SqlParameter("@RigProject", model.RigProject));
         param.Add(new SqlParameter("@LocId", model.LocId));
         param.Add(new SqlParameter("@RigTypeId", model.RigTypeId));
         param.Add(new SqlParameter("@RigModelNo", model.RigModelNo));
         param.Add(new SqlParameter("@RigRemarks", model.RigRemarks));
         param.Add(new SqlParameter("@RigDeployed", model.RigDeployed));
         param.Add(new SqlParameter("@RigLocation", model.RigLocation));
         param.Add(new SqlParameter("@RigTypeName", model.RigTypeName));
         fun.OpenConnection();
         if (fun.getConnection().State == ConnectionState.Open)
         {
             model.RigId = fun.ExecuteQueryWithParameters(query, param, "Yes");
         }
         else
         {
             throw new Exception("Please check connection");
         }
         return(model);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public RigModel Update(RigModel model)
        {
            try
            {
                string query = @"UPDATE Rig SET
                                 RigCode = @RigCode
                                ,RigName = @RigName
                                ,RigManufacturer = @RigManufacturer
                                ,RigProject = @RigProject
                                ,LocId = @LocId
                                ,RigTypeId = @RigTypeId
                                ,RigModelNo = @RigModelNo
                                ,RigRemarks = @RigRemarks
                                ,RigDeployed = @RigDeployed
                                ,RigLocation = @RigLocation
                                ,RigTypeName = @RigTypeName
                                WHERE RigId = @RigId
                                ";
                List <SqlParameter> param = new List <SqlParameter>();
                param.Add(new SqlParameter("@RigId", model.RigId));
                param.Add(new SqlParameter("@RigCode", model.RigCode));
                param.Add(new SqlParameter("@RigName", model.RigName));
                param.Add(new SqlParameter("@RigManufacturer", model.RigManufacturer));
                param.Add(new SqlParameter("@RigProject", model.RigProject));
                param.Add(new SqlParameter("@LocId", model.LocId));
                param.Add(new SqlParameter("@RigTypeId", model.RigTypeId));
                param.Add(new SqlParameter("@RigModelNo", model.RigModelNo));
                param.Add(new SqlParameter("@RigRemarks", model.RigRemarks));
                param.Add(new SqlParameter("@RigDeployed", model.RigDeployed));
                param.Add(new SqlParameter("@RigLocation", model.RigLocation));
                param.Add(new SqlParameter("@RigTypeName", model.RigTypeName));

                fun.OpenConnection();
                if (fun.getConnection().State == ConnectionState.Open)
                {
                    model.RigId = fun.ExecuteQueryWithParameters(query, param, "Yes");
                }
                else
                {
                    throw new Exception("Please check connection");
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }