Ejemplo n.º 1
0
    public static DataTable getDataByModuleIDRelate(int moduleidRL, int BOID, bool isProc, System.Web.UI.Page currentPage, int moduleid, int KeyID)
    {
        try
        {

            string objectnameRelate = getObjectNameFromModuleId(moduleidRL);
            string objectname = getObjectNameFromModuleId(moduleid);
            string KeyfileNameobjectname = getKeyFromModule(moduleid);
            string SQLWhere = "";
            if (KeyID > 0)
            {
                DataSet ds_objectRelation = CacheObject.getGlobalCache("globalObjectRelationship");
                string getkey = string.Format("o1='{0}' AND o2='{1}' AND pk2='{2}'", objectnameRelate, objectname, KeyfileNameobjectname);
                DataRow[] dtr_where = ds_objectRelation.Tables[0].Select(getkey);
                string objectkeyRelate = dtr_where[0]["fk1"].ToString();
                SQLWhere = string.Format("[{0}].[{1}]={2}", objectnameRelate, objectkeyRelate, KeyID).ToLower();
            }

            DataTable dtParamLists = new DataTable();
            string paramstring = "";
            string sql = "";
            if (!checkSQLStringCachebyModuleID(moduleidRL, BOID))
            {
                SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop chưa cache SQL");
                if (!isProc)
                {
                    SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop SQL");

                    EU eu = new EU();
                    sql = eu.getGridDataSource(moduleidRL);
                    object[] result = DynamicQueryBuildParameter(sql, moduleidRL);
                    sql = result[0].ToString();
                    dtParamLists = result[1] as DataTable;
                    SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "SY_SelectSQLCache_insert", moduleidRL, sql, BOID, isProc ? "P" : "Q");

                }
            }
            else
            {
                if (!isProc)
                {
                    SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop SQL");
                    sql = SqlHelper.ExecuteScalar(DataServices.ConnectString, CommandType.Text,
                        string.Format("SELECT sqlstring FROM dbo.SY_SelectSQLCache WHERE moduleid={0}", moduleidRL))
                        .ToString();
                    dtParamLists = getParamsListFromCache(isProc, int.Parse(moduleidRL.ToString()));
                }
            }

            if (sql.IndexOf("where") >= 0)
            {
                int indexof = sql.IndexOf("where");
                sql = sql.Insert(indexof + "where".Length, " " + SQLWhere + " AND ");
            }
            else
            {
                sql = sql + " where " + SQLWhere;
            }

            if (dtParamLists.Rows.Count > 0)
                paramstring = getParamsListToString4SpExecute(dtParamLists, currentPage);
            SiAuto.Main.LogColored(Color.GreenYellow, paramstring);

            DataSet ds = SqlHelper.ExecuteDataset(DataServices.ConnectString, "utils_getDataFromSQL", sql, paramstring, isProc ? "P" : "Q");
            if (ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }
        catch (Exception ex)
        {

            SiAuto.Main.LogColored(Color.Red, ex.ToString());
            return null;
        }
    }
Ejemplo n.º 2
0
    public static DataTable getDataByModuleID(int moduleid, int BOID, bool isProc, System.Web.UI.Page currentPage)
    {
        try
        {

            DataTable dtParamLists = new DataTable();
            string paramstring = "";
            if (!checkSQLStringCachebyModuleID(moduleid, BOID))
            {
                SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop chưa cache SQL");

                string sql = "";

                if (isProc)
                {
                    SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop StoreProc");
                    //lấy storeProc Name để thực hiện
                    sql = ObjectUtils.getObjectNameFromModuleId(moduleid);
                    dtParamLists = SqlHelper.ExecuteDataset(DataServices.ConnectString, "SY_modules_parameter_getByModuleID", new object[] { moduleid }).Tables[0];
                    if (dtParamLists.Rows.Count > 0)
                        paramstring = getParamsListFromSP4SpExecute(dtParamLists, currentPage);
                }
                else
                {
                    SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop SQL");

                    EU eu = new EU();
                    sql = eu.getGridDataSource(moduleid);
                    object[] result = DynamicQueryBuildParameter(sql, moduleid);
                    sql = result[0].ToString();
                    dtParamLists = result[1] as DataTable;
                    if (dtParamLists.Rows.Count > 0)
                        paramstring = getParamsListToString4SpExecute(dtParamLists, currentPage);
                }
                SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "SY_SelectSQLCache_insert", moduleid, sql, BOID, isProc ? "P" : "Q");

                SiAuto.Main.LogDataTable("listParamTable", dtParamLists);

                DataSet ds = SqlHelper.ExecuteDataset(DataServices.ConnectString, "utils_getDataFromSQL", sql, paramstring, isProc ? "P" : "Q");
                if (ds.Tables.Count > 0)
                    return ds.Tables[0];
                else
                    return null;
            }
            else
            {
                isProc = ObjectUtils.getIsStoredFromModuleId(moduleid);
                SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop da cache SQL");

                if (isProc)
                {
                    SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop StoreProc");

                    dtParamLists = SqlHelper.ExecuteDataset(DataServices.ConnectString, "SY_modules_parameter_getByModuleID", new object[] { moduleid }).Tables[0];
                    SiAuto.Main.LogDataTable("Danh sach param trong Module_Params", dtParamLists);
                    if (dtParamLists.Rows.Count > 0)
                        paramstring = getParamsListFromSP4SpExecute(dtParamLists, currentPage);
                }
                else
                {
                    SiAuto.Main.LogColored(Color.Blue, "--> vao truong hop SQL");

                    dtParamLists = getParamsListFromCache(isProc, int.Parse(moduleid.ToString()));
                    if (dtParamLists.Rows.Count > 0)
                        paramstring = getParamsListToString4SpExecute(dtParamLists, currentPage);
                }
                SiAuto.Main.LogColored(Color.GreenYellow, paramstring);

                DataSet ds = SqlHelper.ExecuteDataset(DataServices.ConnectString, "utils_getDatabyModuleID", moduleid, BOID, paramstring);
                if (ds.Tables.Count > 0)
                    return ds.Tables[0];
                else
                    return null;
            }
        }
        catch (Exception ex)
        {

            SiAuto.Main.LogColored(Color.Red, ex.ToString());
            return null;
        }
    }