private string SearchResourceConditionReturn(SearchResourceCard SearchStructure)
 {
     string ConditionReturn = "";
     string DateBase = "1900-01-01";
     if (SearchStructure.txtresourceName != null)
     {
         ConditionReturn += " AND ORGName like (@ORGName) ";
     }
     if (SearchStructure.txtresourceItem != null)
     {
         ConditionReturn += " AND ORGItem like (@ORGItem) ";
     }
     if (SearchStructure.txtaddressCity != null && SearchStructure.txtaddressCity != "0")
     {
         ConditionReturn += " AND AddressCity=(@AddressCity) ";
     }
     if (SearchStructure.txtresourceType != null && SearchStructure.txtresourceType != "0")
     {
         ConditionReturn += " AND Category=(@Category) ";
     }
     StaffDataBase sDB = new StaffDataBase();
     List<string> UserFile = sDB.getStaffDataName(HttpContext.Current.User.Identity.Name);
     if (int.Parse(_StaffhaveRoles[4]) == 0 && UserFile[1].Length > 0)
     {
         ConditionReturn += " AND Unit =" + UserFile[2] + " ";
     }
     return ConditionReturn;
 }
 public string[] SearchResourceDataCount(SearchResourceCard SearchStructure)
 {
     string[] returnValue = new string[2];
     returnValue[0] = "0";
     returnValue[1] = "0";
     DataBase Base = new DataBase();
     string ConditionReturn = this.SearchResourceConditionReturn(SearchStructure);
     using (SqlConnection Sqlconn = new SqlConnection(Base.GetConnString()))
     {
         try
         {
             Sqlconn.Open();
             string sql = "SELECT COUNT(*) AS QCOUNT FROM ResourceCard WHERE isDeleted=0 " + ConditionReturn;
             SqlCommand cmd = new SqlCommand(sql, Sqlconn);
             cmd.Parameters.Add("@ORGName", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(SearchStructure.txtresourceName) + "%";
             cmd.Parameters.Add("@ORGItem", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(SearchStructure.txtresourceItem) + "%";
             cmd.Parameters.Add("@AddressCity", SqlDbType.TinyInt).Value = Chk.CheckStringtoIntFunction(SearchStructure.txtaddressCity);
             cmd.Parameters.Add("@Category", SqlDbType.TinyInt).Value = Chk.CheckStringtoIntFunction(SearchStructure.txtresourceType);
             returnValue[0] = cmd.ExecuteScalar().ToString();
             Sqlconn.Close();
         }
         catch (Exception e)
         {
             returnValue[0] = "-1";
             returnValue[1] = e.Message;
         }
     }
     return returnValue;
 }
Example #3
0
 public string[] searchResourceDataBaseCount(SearchResourceCard SearchData)
 {
     CaseDataBase SDB = new CaseDataBase();
     if (int.Parse(SDB._StaffhaveRoles[3]) == 1)
     {
         return SDB.SearchResourceDataCount(SearchData);
     }
     else
     {
         return new string[2] { _noRole, _errorMsg };
     }
 }
    public List<SearchResourceCardResult> searchResourceDataBase(int indexpage, SearchResourceCard SearchStructure)
    {
        List<SearchResourceCardResult> returnValue = new List<SearchResourceCardResult>();
        DataBase Base = new DataBase();
        string ConditionReturn = this.SearchResourceConditionReturn(SearchStructure);
        using (SqlConnection Sqlconn = new SqlConnection(Base.GetConnString()))
        {
            try
            {
                Sqlconn.Open();
                string sql = "SELECT * FROM (SELECT  ROW_NUMBER() OVER (ORDER BY ID DESC) " +
                             "AS RowNum, * FROM ResourceCard  " +
                             "WHERE isDeleted=0 " + ConditionReturn + " ) " +
                             "AS NewTable " +
                             "WHERE RowNum >= (@indexpage-" + PageMinNumFunction() + ") AND RowNum <= (@indexpage)";
                SqlCommand cmd = new SqlCommand(sql, Sqlconn);
                cmd.Parameters.Add("@indexpage", SqlDbType.Int).Value = indexpage;
                cmd.Parameters.Add("@ORGName", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(SearchStructure.txtresourceName) + "%";
                cmd.Parameters.Add("@ORGItem", SqlDbType.NVarChar).Value = "%" + Chk.CheckStringFunction(SearchStructure.txtresourceItem) + "%";
                cmd.Parameters.Add("@AddressCity", SqlDbType.TinyInt).Value = Chk.CheckStringtoIntFunction(SearchStructure.txtaddressCity);
                cmd.Parameters.Add("@Category", SqlDbType.TinyInt).Value = Chk.CheckStringtoIntFunction(SearchStructure.txtresourceType);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    SearchResourceCardResult addValue = new SearchResourceCardResult();
                    addValue.ID = dr["ID"].ToString();
                    addValue.txtresourceName = dr["ORGName"].ToString();
                    addValue.txtaddressCity = dr["AddressCity"].ToString();
                    addValue.txtresourceType = dr["Category"].ToString();
                    addValue.txtresourceItem = dr["ORGItem"].ToString();
                    returnValue.Add(addValue);

                }
                dr.Close();
                Sqlconn.Close();
            }
            catch (Exception e)
            {
                SearchResourceCardResult addValue = new SearchResourceCardResult();
                addValue.checkNo = "-1";
                addValue.errorMsg = e.Message;
                returnValue.Add(addValue);
            }
        }
        return returnValue;
    }
Example #5
0
 public List<SearchResourceCardResult> searchResourceDataBase(int index, SearchResourceCard SearchData)
 {
     CaseDataBase SDB = new CaseDataBase();
     return SDB.searchResourceDataBase(index, SearchData);
 }