public static string getFirstRow(string strSql)
 {
     MySqlConnection connection = Getconn();
     if (connection == null) throw new ArgumentNullException("connection");
     connection.Open();
     MySqlCommand cmd = new MySqlCommand(strSql, connection);
     MySqlDataAdapter da = new MySqlDataAdapter(cmd);
     DataSet ds = new DataSet();
     da.Fill(ds);
     DataTable dt = ds.Tables[0];
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         if (dt.Rows[i][0] != null)
         {
             da.Dispose();
             cmd.Dispose();
             connection.Close();
             return dt.Rows[i][0].ToString();
         }
     }
     da.Dispose();
     cmd.Dispose();
     connection.Close();
     return null;
 }
Beispiel #2
0
 public DataTable getTags(string pImageId)
 {
     try
     {
         DataTable _dt = new DataTable();
         MySqlDataAdapter _adapter = new MySqlDataAdapter("call spGetImageTags('" + pImageId + "')", GlobalVariables.goMySqlConnection);
         try
         {
             _adapter.Fill(_dt);
             return _dt;
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             _adapter.Dispose();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #3
0
 public DataTable getRolePrivileges(string pRoleName)
 {
     try
     {
         DataTable _dt = new DataTable();
         MySqlDataAdapter _adapter = new MySqlDataAdapter("call spGetRolePrivileges('" + pRoleName + "')", GlobalVariables.goMySqlConnection);
         try
         {
             _adapter.Fill(_dt);
             return _dt;
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             _adapter.Dispose();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Error Message!\r\n" + ex.Message + "\r\nError in : " + this.ToString() + "." + ex.TargetSite + " - " + ex.StackTrace.Substring(ex.StackTrace.IndexOf("line")) + ".");
     }
 }
Beispiel #4
0
 protected DataSet executeSqlCommandDataSet(String sqlCommandStr, List<MySqlParameter> paramList)
 {
     MySqlConnection sqlCon = this.getMySqlConnection();
     try
     {
         sqlCon.Open();
         MySqlCommand sqlCommand = new MySqlCommand(sqlCommandStr, sqlCon);
         if (paramList != null && paramList.Count > 0)
         {
             foreach (MySqlParameter param in paramList)
             {
                 sqlCommand.Parameters.Add(param);
             }
         }
         MySqlDataAdapter sqlAdapter = new MySqlDataAdapter(sqlCommand);
         DataSet ds = new DataSet();
         sqlAdapter.Fill(ds);
         sqlAdapter.Dispose();
         return ds;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         sqlCon.Close();
         sqlCon.Dispose();
     }
 }
 private void GetItemsDataSet(object mangosDB)
 {
     string SQL = "SELECT entry,name FROM item_template;";
     MyReceiverInvoke mi = new MyReceiverInvoke(invokeDataGridView);
     MySqlConnection Conn = new MySqlConnection(sManager.GetConnStr());
     MySqlCommand chgDB = new MySqlCommand("USE " + mangosDB.ToString() + ";", Conn);
     MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
     MySqlDataAdapter adp = new MySqlDataAdapter(SQL, Conn);
     try
     {
         this.Invoke(mi, new object[] { 1, "正在读取物品信息..." });
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         chgDB.ExecuteNonQuery();
         chgDB.Dispose();
         ItemsSet = new DataSet();
         adp.Fill(ItemsSet);
         adp.Dispose();
         if (ItemsSet.Tables[0].Rows.Count == 0)
         {
             throw new Exception("没有找到任何物品!");
         }
         this.Invoke(mi, new object[] { 2, string.Empty });
     }
     catch (Exception err)
     {
         this.Invoke(mi, new object[] { 0, err.Message });
     }
     finally
     {
         Conn.Close();
     }
 }
Beispiel #6
0
 public DataTable get()
 {
     DataTable _dt = new DataTable();
     try
     {
         MySqlDataAdapter _adapter = new MySqlDataAdapter("call spGetDocTypes()", GlobalVariables.goMySqlConnection);
         try
         {
             _adapter.Fill(_dt);
             return _dt;
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             _adapter.Dispose();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #7
0
 public static DataTable GetDataTable(string query)
 {
     command = new MySqlCommand(query, connection);
     MySqlDataAdapter adapter = new MySqlDataAdapter();
     adapter.SelectCommand = command;
     DataTable dataTable = new DataTable();
     adapter.Fill(dataTable);
     adapter.Dispose();
     command.Dispose();
     return dataTable;
 }
Beispiel #8
0
        public string ConnectionTest()
        {
            s = ConfigurationManager.AppSettings["MySql"].ToString();
            MySqlConnection mysqlcon = new MySqlConnection(s);
            MySqlCommand mysqlcom = new MySqlCommand("", mysqlcon);
            MySqlDataAdapter mysqldataadp = new MySqlDataAdapter(mysqlcom);
            DataSet ds=new DataSet();
            string message = "";
            try
            {
                //mysqlcon.Open();
                if (mysqlcon.State != ConnectionState.Open)
                {
                    mysqlcon.Open();
                }
                mysqldataadp.SelectCommand.CommandText="select * from ow_articletype";
                message = "打开数据库成功!";
                mysqldataadp.Fill(ds);

                if (ds.Tables.Count > 0)
                {
                    message = ds.Tables[0].Rows[0][1].ToString();
                }
                else
                {
                    message = "可惜查不到数据";
                }
            }
            catch (Exception ex)
            {
                if(mysqlcon.State==ConnectionState.Open)
                {
                    mysqlcon.Close();
                    mysqlcon.Dispose();
                }
                message = "数据库访问失败! 信息:"+ex.Message;
            }
            finally
            {
                if (mysqlcon.State == ConnectionState.Open)
                {
                    mysqlcon.Close();
                }
                mysqlcon.Dispose();
                mysqlcom.Dispose();
                mysqldataadp.Dispose();
            }
            return message;
        }
        public DataTable ExecuteQuery(string sql, ITransaction transaction, Action<IParameterAdder> paramaterLoader)
        {
            Log.Info("Sql:" + sql);
            InvokeOnSqlExecute(new OnSqlExecuteDeligateArgs(sql));
            if (sql == null) throw new ArgumentNullException("sql");

            var mySqlTransactionWrapper = transaction as MySqlTransactionWrapper;
            var mySqlCommand = new MySqlCommand(sql, _sqlConnection, mySqlTransactionWrapper != null ? mySqlTransactionWrapper.Transaction : null);
            paramaterLoader(new MysqlParaAdder(mySqlCommand.Parameters));
            var sqlDataAdapter = new MySqlDataAdapter(mySqlCommand);
            var dtResult = new DataTable();
            sqlDataAdapter.Fill(dtResult);
            sqlDataAdapter.Dispose();
            return dtResult;
        }
Beispiel #10
0
        /// <summary>
        ///  cambia la imagen del usuario con los parametros nombre de la nueva imagen 
        ///  el id del usuario a cambiar y la direccion de la imagen ya guardada para eliminar anterior
        /// </summary>
        /// <param name="imagen"></param>
        /// <param name="id_user"></param>
        /// <param name="server_path"></param>
        /// <returns> regresa el nombre de la imagen en caso todo salio bien , regresa null en caso de que hubo un problema</returns>
        public string CambiarImagen(string imagen , string id_user , string server_path)
        {
            try
            {
                string imagen_anterior = null;
                Conexion conn = new Conexion();
                conn.IniciarConexion();
                if (conn.GetConexion == null) return null;
                string sql = "select imagen from user where id_user like '" + id_user + "'";
                MySqlDataAdapter adaptador = new MySqlDataAdapter(sql, conn.GetConexion);
                DataSet ds = new DataSet();
                adaptador.Fill(ds);
                DataTable tabla = ds.Tables[0];
                foreach (DataRow rows in tabla.Rows)
                {
                    imagen_anterior = rows.Field<string>("imagen", DataRowVersion.Default);
                }
                adaptador.Dispose();
                ds.Dispose();
                tabla.Dispose();
                sql = "Update user set imagen = '" + imagen + "' where id_user like '" + id_user + "'";
                MySqlCommand cmd = new MySqlCommand(sql, conn.GetConexion);
                MySqlDataReader read = cmd.ExecuteReader();
                if (read.RecordsAffected >= 1)
                {
                    if (imagen_anterior != " NULL"
                        || imagen_anterior != "NULL"
                        || imagen_anterior != ""
                        || imagen_anterior != " ")
                    {

                        string ruta = System.IO.Path.Combine(server_path, imagen_anterior);
                        System.IO.File.Delete(ruta);
                    }
                    conn.CerrarConexion();
                    return imagen;
                }
                else
                {
                    conn.CerrarConexion();
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
Beispiel #11
0
 public DataTable get()
 {
     try
     {
         string _sql = "call spGetEmployeeTypes()";
         loMySqlDataAdapter = new MySqlDataAdapter(_sql, GlobalVariables.goMySqlConnection);
         loDataTable = new DataTable("EmployeeTypes");
         loMySqlDataAdapter.Fill(loDataTable);
         return loDataTable;
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         loMySqlDataAdapter.Dispose();
     }
 }
Beispiel #12
0
        public DataSet SqlCommand(string sqlCommand)
        {
            ds = new DataSet();
            try
            {
                using (MySqlDataAdapter dataAdapter =
                new MySqlDataAdapter(sqlCommand, connectString))
                {
                    dataAdapter.Fill(ds, "list");
                    dataAdapter.Dispose();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            return ds;
        }
Beispiel #13
0
        public DataTable getDetailsByID(string pUserId)
        {
            try
            {
                string _sql = "call spGetUserDetailsById('" + pUserId + "')";
                loMySqlDataAdapter = new MySqlDataAdapter(_sql, GlobalVariables.goMySqlConnection);
                DataTable _dt = new DataTable();
                loMySqlDataAdapter.Fill(_dt);
                return _dt;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                loMySqlDataAdapter.Dispose();
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        cnString  = ConfigurationSettings.AppSettings["connectionstring"].ToString();

        String version = Request.QueryString["version"];
        String AppId = Request.QueryString["AppId"]; // TODO - not needed for now

        string sqlstring ;
        if (version == null)
        {
            sqlstring = "SELECT * FROM categories where id <> 2 order by ordering DESC";

        }
        else if( AppId.Equals("2") )
        {
            sqlstring = "SELECT * FROM categories where off=0 order by ordering DESC";
        }
        else
        {
            sqlstring = "SELECT * FROM categories order by ordering DESC";
        }

        MySqlConnection cn = new MySqlConnection(cnString);
        MySqlDataAdapter dr = new MySqlDataAdapter(sqlstring, cn);
        try
        {
            DataSet ds = new DataSet();
            dr.Fill(ds);
            string jsonString = JsonConvert.SerializeObject(ds.Tables[0]);
            Response.Write(jsonString);
        }
        finally
        {
            //  Explicitly dispose the SelectCommand instance
            dr.SelectCommand.Dispose();
            dr.Dispose();
            cn.Close();
        }

        Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
    }
Beispiel #15
0
        public DataTable get(string pNewspaperId)
        {
            try
            {
                string _sql = "call spGetSections('" + pNewspaperId + "')";

                loMySQLDataAdapter = new MySqlDataAdapter(_sql, GlobalVariables.goMySqlConnection);
                loDataTable = new DataTable("Sections");
                loMySQLDataAdapter.Fill(loDataTable);
                return loDataTable;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                loMySQLDataAdapter.Dispose();
            }
        }
Beispiel #16
0
        /*.........................
        btnHistory_Click - resize the form to reliese the history datagridview
        .........................*/
        private void btnHistory_Click(object sender, EventArgs e)
        {
            if (this.Width == 393)
            {
                this.Width = 825;
                btnHistory.Text = "Hide History";
            }
            else if (this.Width == 825)
            {
                this.Width = 393;
                btnHistory.Text = "History";
            }

            MySqlDataAdapter gridAdapter = new MySqlDataAdapter("SELECT id, kcal, min,weight, num_day, week, day_today FROM records WHERE user_id = " + HomePage.iUserId + " ORDER BY id;", connStr);
            DataTable gridTable = new DataTable();
            gridAdapter.Fill(gridTable);

            //fill the grid with all the user's activities
            dataUserHistory.DataSource = gridTable;

            gridAdapter.Dispose();
        }
    public override void Execute(string sql, ResultHandler resultHandler, ErrorHandler errorHandler)
    {
        #if DEBUG
        Console.WriteLine("Execute: {0}", sql);
        #endif
        string result = null;
        DataTable dt = null;
        if ((result = Connect()) != null) {
            if (errorHandler != null) {
                //TODO: Move this into Connect() itself
                errorHandler(result, null);
            }
            return;
        }

        try {
            MySqlDataAdapter da = new MySqlDataAdapter(sql, _con);
            dt = new DataTable();
            da.Fill(dt);
            da.Dispose();
            da = null;
        #if DEBUG
            dt.TableName = "Result";
            using(var writer = new System.IO.StringWriter()) {
                dt.WriteXml(writer);
                Console.WriteLine(writer.ToString());
            }
        #endif
        } catch (Exception e) {
            Console.WriteLine("Exception querying DB: {0}", e.Message);
            if (errorHandler != null) {
                errorHandler(e.Message, e);
            }
        }
        if (resultHandler != null) {
            resultHandler(dt);
        }
    }
Beispiel #18
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                if (data != null)
                {
                    data.Dispose();
                }
                if (ds != null)
                {
                    ds.Dispose();
                }
                if (da != null)
                {
                    da.Dispose();
                }
                if (cb != null)
                {
                    cb.Dispose();
                }
                if (com != null)
                {
                    com.Dispose();
                }
                if (comm != null)
                {
                    comm.Dispose();
                }
            }
            disposed = true;
        }
Beispiel #19
0
        public DataTable Query(string query, bool logerror = true)
        {
            try
            {
                if(_crash)
                    return null;

                IsConnect();
                var adapter = new MySqlDataAdapter();
                var command = Connection.CreateCommand();
            #if DEBUG
                _debuglog.LogInFile(query);
            #endif
                command.CommandText = query;
                adapter.SelectCommand = command;

                var table = new DataTable();
                adapter.Fill(table);

                command.Dispose();
                adapter.Dispose();

                return table;
            }
            catch(MySqlException m)
            {
                Crash(m, logerror);
                return null;
            }
        }
        private void AddChilds(Item newItem) {
            DataSet ds = new DataSet();

            using (MySqlConnection connection = new MySqlConnection(MyConnectionString)) {
                MySqlCommand cmd = connection.CreateCommand();
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT WP1.ID AS 'PostID', wp1.post_author, wp1.post_title, wp1.post_content, " +
                                   "wp1.post_status, wp1.post_name, wp1.post_type, wp1.R1.slug AS 'language' FROM wp_posts wp1 " +
                                   "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                   "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                   "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                   "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                   "WHERE wtt1.taxonomy = 'language' AND wp1.post_type='" + this.PostType + "'  ) R1 ON R1.ID = wp1.ID " +
                                   "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                   "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                   "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                   "WHERE wtt1.taxonomy = 'post_translations' AND wt1.slug  IN (  " +
                                   "SELECT " +
                                   "DISTINCT R1.slug " +
                                   "FROM wp_posts p " +
                                   "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                   "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                   "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                   "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                   "WHERE wtt1.taxonomy = 'post_translations' ) R1 ON R1.ID = p.ID " +
                                   "INNER JOIN wp_postmeta wp ON p.ID = wp.post_id " +
                                   "INNER JOIN wp_term_relationships wtr ON p.ID = wtr.object_id " +
                                   "INNER JOIN wp_term_taxonomy wtt ON wtr.term_taxonomy_id = wtt.term_taxonomy_id " +
                                   "INNER JOIN wp_terms wt ON wt.term_id = wtt.term_id AND p.ID =" + ChildPostID + " And p.post_type = '" + this.PostType + "') " +
                                   "AND wp1.ID =" + ChildPostID + " AND R1.slug = 'en' " +
                                   "ORDER BY wp1.ID;");
                sb.Append(" SELECT A.ID AS 'PostID', A.post_author, A.post_title, A.post_content, " +
                                    "A.post_status, A.post_name, A.post_type, 'en' AS 'language' FROM wp_posts AS A WHERE A.post_type='" + this.PostType + "' AND A.ID NOT IN ( " +
                                    "SELECT DISTINCT WP1.ID AS 'PostID' " +
                                    "FROM wp_posts wp1 " +
                                    "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                    "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                    "WHERE wtt1.taxonomy = 'language' AND wp1.post_type='" + this.PostType + "'  ) R1 ON R1.ID = wp1.ID " +
                                    "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                    "WHERE wtt1.taxonomy = 'post_translations' AND wt1.slug  IN (  " +
                                    "SELECT " +
                                    "DISTINCT R1.slug " +
                                    "FROM wp_posts p " +
                                    "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                    "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                    "WHERE wtt1.taxonomy = 'post_translations' ) R1 ON R1.ID = p.ID " +
                                    "INNER JOIN wp_postmeta wp ON p.ID = wp.post_id " +
                                    "INNER JOIN wp_term_relationships wtr ON p.ID = wtr.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt ON wtr.term_taxonomy_id = wtt.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt ON wt.term_id = wtt.term_id AND p.ID =" + ChildPostID + " And p.post_type = '" + this.PostType + "') " +
                                    "AND R1.slug = 'en') AND A.ID = " + ChildPostID + " ORDER BY A.ID;");
               
                cmd.CommandText = sb.ToString();
                cmd.CommandTimeout = 99900;

                connection.Open();
                MySqlDataAdapter adap;
                adap = new MySqlDataAdapter(cmd);
                adap.Fill(ds);
                cmd.Dispose();
                adap.Dispose();
                connection.Close();
            }

            if (ds != null && ds.Tables.Count > 0) {
                foreach (DataTable dt in ds.Tables) {
                    DataTable datasource = dt;

                    foreach (DataRow dr in datasource.Rows) {
                        this.DefaultLanguagePostID = this.CurrentPostID = dr["PostID"].ToString();
                        this.CurrentLanguage = dr["language"].ToString();
                        this.PageTitle = dr["post_title"].ToString().Trim();

                        Item newChildItem = this.CreateItem(newItem);
                        this.AddDifferentLanguageVerstion(newChildItem);
                        if (this.PostType == "checklist_repeater") {
                            this.CreateTopicCheckBoxItem(newChildItem);
                        }
                    }
                }
            }
            ds.Dispose();

        }
        private string GetQuizType(string postID) {
            DataSet ds = new DataSet();
            string quizType = string.Empty;
            using (MySqlConnection connection = new MySqlConnection(MyConnectionString)) {
                MySqlCommand cmd = connection.CreateCommand();
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT wp1.post_id, wp1.meta_key, wp1.meta_value " +
                            "FROM wp_posts wp " +
                            "INNER JOIN wp_postmeta wp1 ON wp.ID = wp1.post_id " +
                            "WHERE wp.ID IN (" + postID + ") AND wp1.meta_key ='wpcf-quiz-type'");
                cmd.CommandText = sb.ToString();
                cmd.CommandTimeout = 99990;

                connection.Open();
                MySqlDataAdapter adap;
                adap = new MySqlDataAdapter(cmd);
                adap.Fill(ds);
                cmd.Dispose();
                adap.Dispose();
                connection.Close();
            }

            if (ds != null && ds.Tables.Count > 0) {
                DataTable datasource = ds.Tables[0];

                foreach (DataRow varrow in datasource.Rows) {
                    quizType = varrow["meta_value"].ToString();

                }
            }
            ds.Dispose();

            return quizType;
        }
        private void AddQuestion(Item ParentRootItem, string postId) {
            this.Template_Import = "/sitecore/templates/User Defined/Poses/Pages/Article Pages/Base for Quiz/Quiz Question";
            Item questionItem = this.CreateItem(ParentRootItem);
            this.AddDifferentLanguageVerstion(questionItem);

            DataSet ds = new DataSet();

            using (MySqlConnection connection = new MySqlConnection(MyConnectionString)) {
                MySqlCommand cmd = connection.CreateCommand();
                StringBuilder sb = new StringBuilder();

                sb.Append("SELECT wp1.post_id, wp1.meta_key, wp1.meta_value " +
                            "FROM wp_posts wp " +
                            "INNER JOIN wp_postmeta wp1 ON wp.ID = wp1.post_id " +
                            "WHERE wp.ID = " + postId);
                cmd.CommandText = sb.ToString();
                connection.Open();
                MySqlDataAdapter adap;
                adap = new MySqlDataAdapter(cmd);
                adap.Fill(ds);
                cmd.Dispose();
                adap.Dispose();
                connection.Close();
            }

            if (ds != null && ds.Tables.Count > 0) {
                DataTable datasource = ds.Tables[0];

                this.Template_Import = "/sitecore/templates/User Defined/Poses/Pages/Article Pages/Base for Quiz/Quiz Answers";
                //QuesAnsfields
                QuesAnsfields = new Dictionary<string, string>();
                Dictionary<string, string> Quesfields = new Dictionary<string, string>();
                Dictionary<string, string> Ansfields1 = new Dictionary<string, string>();
                Dictionary<string, string> Ansfields2 = new Dictionary<string, string>();
                Dictionary<string, string> Ansfields3 = new Dictionary<string, string>();
                Dictionary<string, string> Ansfields4 = new Dictionary<string, string>();
                Dictionary<string, string> Ansfields5 = new Dictionary<string, string>();
                foreach (DataRow varrow in datasource.Rows) {
                    switch (varrow["meta_key"].ToString()) {
                        case "wpcf-question-field-type":
                            Quesfields.Add("Question Type", varrow["meta_value"].ToString());
                            break;

                        case "wpcf-points-for-this-answer-option-1":
                            Ansfields1.Add("Score", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-correct-answer-option-1":
                            Ansfields1.Add("True Answer", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-incorrect-answer-option-1":
                            Ansfields1.Add("False Answer", varrow["meta_value"].ToString());
                            break;

                        case "wpcf-points-for-this-answer-option-2":
                            Ansfields2.Add("Score", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-correct-answer-option-2":
                            Ansfields2.Add("True Answer", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-incorrect-answer-option-2":
                            Ansfields2.Add("False Answer", varrow["meta_value"].ToString());
                            break;

                        case "wpcf-points-for-this-answer-option-3":
                            Ansfields3.Add("Score", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-correct-answer-option-3":
                            Ansfields3.Add("True Answer", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-incorrect-answer-option-3":
                            Ansfields3.Add("False Answer", varrow["meta_value"].ToString());
                            break;

                        case "wpcf-points-for-this-answer-option-4":
                            Ansfields4.Add("Score", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-correct-answer-option-4":
                            Ansfields4.Add("True Answer", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-incorrect-answer-option-4":
                            Ansfields4.Add("False Answer", varrow["meta_value"].ToString());
                            break;

                        case "wpcf-points-for-this-answer-option-5":
                            Ansfields5.Add("Score", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-correct-answer-option-5":
                            Ansfields5.Add("True Answer", varrow["meta_value"].ToString());
                            break;
                        case "wpcf-message-with-incorrect-answer-option-5":
                            Ansfields5.Add("False Answer", varrow["meta_value"].ToString());
                            break;
                    }
                }

                foreach (DataRow varrow in datasource.Rows) {
                    switch (varrow["meta_key"].ToString()) {

                        //wpcf-question-field-type
                        //wpcf-is-correct-option
                        //wpcf-question-image

                        //break;
                        case "wpcf-answer-text-option-1":
                            if (!string.IsNullOrEmpty(varrow["meta_value"].ToString())) {
                                this.ArticleItemName = "Answer-1";
                                Item ans1 = this.CreateItem(questionItem);
                                this.AddDifferentLanguageVerstion(ans1);
                            }
                            break;
                        //wpcf-points-for-this-answer-option-1
                        //wpcf-message-with-correct-answer-option-1
                        //wpcf-message-with-incorrect-answer-option-1
                        case "wpcf-answer-text-option-2":
                            if (!string.IsNullOrEmpty(varrow["meta_value"].ToString())) {
                                this.ArticleItemName = "Answer-2";
                                Item ans2 = this.CreateItem(questionItem);
                                this.AddDifferentLanguageVerstion(ans2);
                            }
                            break;
                        //wpcf-points-for-this-answer-option-2
                        //wpcf-message-with-correct-answer-option-2
                        //wpcf-message-with-incorrect-answer-option-2
                        case "wpcf-answer-text-option-3":
                            if (!string.IsNullOrEmpty(varrow["meta_value"].ToString())) {
                                this.ArticleItemName = "Answer-3";
                                Item ans3 = this.CreateItem(questionItem);
                                this.AddDifferentLanguageVerstion(ans3);
                            }
                            break;
                        //wpcf-message-with-correct-answer-option-3
                        //wpcf-message-with-incorrect-answer-option-3
                        //wpcf-points-for-this-answer-option-3
                        case "wpcf-answer-text-option-4":
                            if (!string.IsNullOrEmpty(varrow["meta_value"].ToString())) {
                                this.ArticleItemName = "Answer-4";
                                Item ans4 = this.CreateItem(questionItem);
                                this.AddDifferentLanguageVerstion(ans4);
                            }
                            break;
                        //wpcf-points-for-this-answer-option-4
                        //wpcf-message-with-correct-answer-option-4
                        //wpcf-message-with-incorrect-answer-option-4
                        case "wpcf-answer-text-option-5":
                            if (!string.IsNullOrEmpty(varrow["meta_value"].ToString())) {
                                this.ArticleItemName = "Answer-5";
                                Item ans5 = this.CreateItem(questionItem);
                                this.AddDifferentLanguageVerstion(ans5);
                            }
                            break;
                        //wpcf-points-for-this-answer-option-5
                        //wpcf-message-with-correct-answer-option-5
                        //wpcf-message-with-incorrect-answer-option-5
                    }
                }
            }
            ds.Dispose();

        }
Beispiel #23
0
    public Dictionary<int, List<Program>> GetProgramsForAllChannels(DateTime startTime, DateTime endTime,
                                                                    List<Channel> channelList)
    {
      MySqlConnection MySQLConnect = null;
      MySqlDataAdapter MySQLAdapter = null;
      MySqlCommand MySQLCmd = null;

      SqlDataAdapter MsSqlAdapter = null;
      SqlConnection MsSqlConnect = null;
      SqlCommand MsSqlCmd = null;
      string provider = "";
      try
      {
        string connectString;
        try
        {
          provider = ProviderFactory.GetDefaultProvider().Name.ToLowerInvariant();
          connectString = ProviderFactory.GetDefaultProvider().ConnectionString;
        }
        catch (Exception cex)
        {
          Log.Info("BusinessLayer: GetProgramsForAllChannels could not retrieve connection details - {0}", cex.Message);
          return new Dictionary<int, List<Program>>();
        }
        switch (provider)
        {
          case "sqlserver":
            MsSqlConnect = new SqlConnection(connectString);
            MsSqlAdapter = new SqlDataAdapter();
            MsSqlAdapter.TableMappings.Add("Table", "Program");
            MsSqlConnect.Open();
            MsSqlCmd = new SqlCommand(BuildEpgSelect(channelList, provider), MsSqlConnect);
            MsSqlCmd.Parameters.Add("startTime", SqlDbType.DateTime).Value = startTime;
            MsSqlCmd.Parameters.Add("endTime", SqlDbType.DateTime).Value = endTime;
            MsSqlAdapter.SelectCommand = MsSqlCmd;
            break;
          case "mysql":
            MySQLConnect = new MySqlConnection(connectString);
            MySQLAdapter = new MySqlDataAdapter(MySQLCmd);
            MySQLAdapter.TableMappings.Add("Table", "Program");
            MySQLConnect.Open();
            MySQLCmd = new MySqlCommand(BuildEpgSelect(channelList, provider), MySQLConnect);
            MySQLCmd.Parameters.Add("?startTime", MySqlDbType.DateTime).Value = startTime;
            MySQLCmd.Parameters.Add("?endTime", MySqlDbType.DateTime).Value = endTime;
            MySQLAdapter.SelectCommand = MySQLCmd;
            break;
          default:
            return new Dictionary<int, List<Program>>();
        }

        using (DataSet dataSet = new DataSet("Program"))
        {
          switch (provider)
          {
            case "sqlserver":
              if (MsSqlAdapter != null)
              {
                MsSqlAdapter.Fill(dataSet);
              }
              break;
            case "mysql":
              if (MySQLAdapter != null)
              {
                MySQLAdapter.Fill(dataSet);
              }
              break;
          }
          return FillProgramMapFromDataSet(dataSet);
        }
      }
      catch (Exception ex)
      {
        Log.Info("BusinessLayer: GetProgramsForAllChannels caused an Exception - {0}, {1}", ex.Message, ex.StackTrace);
        return new Dictionary<int, List<Program>>();
      }
      finally
      {
        try
        {
          switch (provider)
          {
            case "mysql":
              if (MySQLConnect != null)
              {
                MySQLConnect.Close();
              }
              if (MySQLAdapter != null)
              {
                MySQLAdapter.Dispose();
              }
              if (MySQLCmd != null)
              {
                MySQLCmd.Dispose();
              }
              if (MySQLConnect != null)
              {
                MySQLConnect.Dispose();
              }
              break;
            case "sqlserver":
              if (MsSqlConnect != null)
              {
                MsSqlConnect.Close();
              }
              if (MsSqlAdapter != null)
              {
                MsSqlAdapter.Dispose();
              }
              if (MsSqlCmd != null)
              {
                MsSqlCmd.Dispose();
              }
              if (MsSqlConnect != null)
              {
                MsSqlConnect.Dispose();
              }
              break;
          }
        }
        catch (Exception ex)
        {
          Log.Info("BusinessLayer: GetProgramsForAllChannels Exception in finally - {0}, {1}", ex.Message, ex.StackTrace);
        }
      }
    }
 public static bool isEmailIDExist_getItsID(string emailID, string sp_name, out string error, out string id)
 {
     try
     {
         using (MySqlConnection connection = new ConnectionManager().GetDatabaseConnection())
         {
             using (MySqlCommand command = new MySqlCommand(sp_name, connection))
             {
                 command.CommandType = CommandType.StoredProcedure;
                 command.Parameters.Add("@e", MySqlDbType.VarChar).Value = emailID;
                 MySqlDataAdapter adapter = new MySqlDataAdapter();
                 DataTable dt = new DataTable();
                 connection.Open();
                 adapter.SelectCommand = command;
                 adapter.Fill(dt);
                 connection.Close();
                 adapter.Dispose();
                 if (dt.Rows.Count == 1)
                 {
                     error = null;
                     id = dt.Rows[0].ItemArray[0].ToString();
                     return true;
                 }
                 else {
                     error = null;
                     id = null;
                     return false;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         error = ex.Message;
         id = null;
         return true;
     }
 }
        private Boolean getImage(String ID)
        {
            Boolean result = false;
            using (MySqlConnection conn = new MySqlConnection(connectionManager.connectionString))
            {
                try
                {
                    var id = int.Parse(ID);
                    conn.Open();

                    string query = "SELECT Image FROM student_img WHERE ID =  @ID";

                    MySqlCommand cmd = new MySqlCommand(query, conn);

                    cmd.Parameters.AddWithValue("@ID", id);

                    var da = new MySqlDataAdapter(cmd);

                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    //textBoxID.Text = dt.Rows[0][0].ToString();
                    //textBoxNAME.Text = dt.Rows[0][1].ToString();
                    //textBoxDescription.Text = dt.Rows[0][2].ToString();
                    //set image from mysql database to pictureBox
                    int count = dt.Rows.Count;
                    if (count > 0)
                    {
                        byte[] img = (byte[])dt.Rows[0][0];
                        MemoryStream ms = new MemoryStream(img);

                        if (ms.Length == 0)
                        {
                            picLogo.ImageLocation = "https://placeholdit.imgix.net/~text?txtsize=40&bg=262835&txtclr=ffffff&txt=Image+Not+Available&w=200&h=218";
                        }

                        else {

                            picLogo.Image = Image.FromStream(ms);
                            da.Dispose();
                            result = true;
                            }
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error in getImage\n" + ex.Message, "Error Message",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);

                }
            }
            return result;
        }
 private async void GetOverViewCalls()
 {
     try
     {
         DataTable dataFromDB = new DataTable();
         using (MySqlConnection dbConn = new MySqlConnection("Server=" + ICResponse.Properties.Settings.Default.DBServer +
                                                             ";Database=" + ICResponse.Properties.Settings.Default.DBName +
                                                             ";Uid=" + ICResponse.Properties.Settings.Default.DBUser +
                                                             ";Pwd=" + ICResponse.Properties.Settings.Default.DBPass +
                                                             ";Convert Zero Datetime=True;"))
         {
             using (MySqlDataAdapter dbDataAdapter = new MySqlDataAdapter(ICResponse.Properties.Settings.Default.GetOverview, dbConn))
             {
                 dbConn.Open();
                 await dbDataAdapter.FillAsync(dataFromDB);
                 OverViewCallsGrid.ItemsSource = dataFromDB.DefaultView;
                 dbDataAdapter.Dispose();                        
             }
             dbConn.Close();
         }                              
     }
     catch (MySqlException me)
     {
         System.Diagnostics.Debug.WriteLine(me);
         throw;                
     }
 }
        private void AddDifferentLanguageVerstion(Item newItem) {
            DataSet ds = new DataSet();
            Dictionary<string, string> fields = new Dictionary<string, string>();

            using (MySqlConnection connection = new MySqlConnection(MyConnectionString)) {
                MySqlCommand cmd = connection.CreateCommand();
                string getPostQuery = "SELECT WP1.ID, wp1.post_author, wp1.post_title, wp1.post_content, wp1.post_status, wp1.post_name, wp1.post_type, R1.slug AS 'language' FROM wp_posts wp1 " +
                                    "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                    "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                    "WHERE wtt1.taxonomy = 'language' AND wp1.post_type='" + this.PostType + "' ) R1 ON R1.ID = wp1.ID " +
                                    "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                    "WHERE wtt1.taxonomy = 'post_translations' AND wt1.slug  IN (  " +
                                    "SELECT " +
                                    "DISTINCT R1.slug " +
                                    "FROM wp_posts p " +
                                    "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                    "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                    "WHERE wtt1.taxonomy = 'post_translations' ) R1 ON R1.ID = p.ID " +
                                    "INNER JOIN wp_postmeta wp ON p.ID = wp.post_id " +
                                    "INNER JOIN wp_term_relationships wtr ON p.ID = wtr.object_id " +
                                    "INNER JOIN wp_term_taxonomy wtt ON wtr.term_taxonomy_id = wtt.term_taxonomy_id " +
                                    "INNER JOIN wp_terms wt ON wt.term_id = wtt.term_id AND p.post_type = '" + this.PostType + "' AND " +
                                    "p.ID = " + DefaultLanguagePostID + ") " +
                                    "AND R1.slug  <> 'en' AND  wp1.post_type = '" + this.PostType + "'" +
                                    "ORDER BY wp1.ID";
                connection.Open();
                cmd.CommandText = getPostQuery;
                cmd.CommandTimeout = 99900;

                MySqlDataAdapter adap = new MySqlDataAdapter(cmd);

                adap.Fill(ds);
                cmd.Dispose();
                adap.Dispose();
                connection.Close();
            }
            if (ds != null && ds.Tables.Count > 0) {
                DataTable datasource = ds.Tables[0];

                foreach (DataRow dr in datasource.Rows) {
                    this.CurrentPostID = dr["ID"].ToString();
                    this.CurrentLanguage = dr["language"].ToString();
                    this.PageTitle = dr["post_title"].ToString();
                    this.AddItemVerstion(newItem);
                }
            }
            ds.Dispose();
        }
Beispiel #28
0
        internal static DataTable ExecuteTable(string sql, string connStr)
        {
            MySqlCommand cmd = new MySqlCommand();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            adapter.SelectCommand = cmd;
            DataTable dt = new DataTable();

            try
            {
                MySqlConnection conn = GetConnection(connStr);

                cmd.Connection = conn;
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                cmd.CommandTimeout = 240;

                adapter.Fill(dt);
                adapter.Dispose();

                cmd.Dispose();
                conn.Close();
            }
            catch (Exception ex)
            {
                dt = new DataTable();
            }
            return dt;
        }
        private void GetPosts() {
            DataSet ds = new DataSet();

            using (MySqlConnection connection = new MySqlConnection(MyConnectionString)) {
                MySqlCommand cmd = connection.CreateCommand();
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT WP1.ID AS 'PostID', wp1.post_author, wp1.post_title, wp1.post_content, " +
                                     "wp1.post_status, wp1.post_name, wp1.post_type, wp1.R1.slug AS 'language' FROM wp_posts wp1 " +
                                     "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                     "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                     "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                     "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                     "WHERE wtt1.taxonomy = 'language' AND wp1.post_type='" + this.PostType + "' ) R1 ON R1.ID = wp1.ID " +
                                     "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                     "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                     "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                     "WHERE wtt1.taxonomy = 'post_translations' AND wt1.slug  IN (  " +
                                     "SELECT " +
                                     "DISTINCT R1.slug " +
                                     "FROM wp_posts p " +
                                     "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                                     "INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                                     "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                                     "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                                     "WHERE wtt1.taxonomy = 'post_translations' ) R1 ON R1.ID = p.ID " +
                                     "INNER JOIN wp_postmeta wp ON p.ID = wp.post_id " +
                                     "INNER JOIN wp_term_relationships wtr ON p.ID = wtr.object_id " +
                                     "INNER JOIN wp_term_taxonomy wtt ON wtr.term_taxonomy_id = wtt.term_taxonomy_id " +
                                     "INNER JOIN wp_terms wt ON wt.term_id = wtt.term_id AND p.post_type = '" + this.PostType + "') " +
                                     "AND R1.slug = 'en'  ORDER BY wp1.ID;");

                //AND wp1.ID=4134
                sb.Append(" SELECT A.ID AS 'PostID', A.post_author, A.post_title, A.post_content, " +
                  "A.post_status, A.post_name, A.post_type, 'en' AS 'language' FROM wp_posts AS A WHERE A.post_type='" + this.PostType + "' AND A.ID NOT IN ( " +
                  "SELECT DISTINCT WP1.ID " +
                  "FROM wp_posts wp1 INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                  "INNER JOIN wp_term_relationships wtr1 " +
                  "ON Wp1.ID = wtr1.object_id " +
                  "INNER JOIN wp_term_taxonomy wtt1 " +
                  "ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                  "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                  "WHERE wtt1.taxonomy = 'language' AND wp1.post_type='" + this.PostType + "') " +
                  "R1 ON R1.ID = wp1.ID INNER JOIN wp_term_relationships wtr1 ON Wp1.ID = wtr1.object_id " +
                  "INNER JOIN wp_term_taxonomy wtt1 ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                  "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                  "WHERE wtt1.taxonomy = 'post_translations' AND wt1.slug " +
                  "IN (SELECT DISTINCT R1.slug FROM wp_posts p " +
                  "INNER JOIN (SELECT WP1.ID, wt1.slug FROM wp_posts wp1 " +
                  "INNER JOIN wp_term_relationships wtr1 ON  " +
                  "Wp1.ID = wtr1.object_id " +
                  "INNER JOIN wp_term_taxonomy wtt1 " +
                  "ON wtr1.term_taxonomy_id = wtt1.term_taxonomy_id " +
                  "INNER JOIN wp_terms wt1 ON wt1.term_id = wtt1.term_id " +
                  "WHERE wtt1.taxonomy = 'post_translations' ) R1 ON R1.ID = p.ID " +
                  "INNER JOIN wp_postmeta wp ON p.ID = wp.post_id " +
                  "INNER JOIN wp_term_relationships wtr ON p.ID = wtr.object_id " +
                  "INNER JOIN wp_term_taxonomy wtt ON wtr.term_taxonomy_id = wtt.term_taxonomy_id " +
                  "INNER JOIN wp_terms wt ON wt.term_id = wtt.term_id AND p.post_type = '" + this.PostType + "') " +
                  "AND R1.slug = 'en' ) ORDER BY A.ID; ");
                //AND A.ID=4134
                connection.Open();
                cmd.CommandTimeout = 99999;
                cmd.CommandText = sb.ToString();
                MySqlDataAdapter adap = new MySqlDataAdapter(cmd);

                adap.Fill(ds);
                cmd.Dispose();
                adap.Dispose();
                connection.Close();
            }

            if (ds != null && ds.Tables.Count > 0) {
                int i = 0;
                int assessment = 0;
                int knowledge = 0;
                foreach (DataTable dt in ds.Tables) {
                    DataTable datasource = dt;
                    DataTable tops = null;
                    if (datasource.Rows.Count > 0) {
                        tops = datasource.Rows.Cast<System.Data.DataRow>().CopyToDataTable();
                        //tops = datasource.Rows.Cast<System.Data.DataRow>().Take(1).CopyToDataTable();
                    }

                    if (tops != null && tops.Rows.Count > 0) {

						using (new BulkUpdateContext()) {
							foreach (DataRow dr in tops.Rows) {
								i++;
								this.DefaultLanguagePostID = this.CurrentPostID = dr["PostID"].ToString();
								this.CurrentLanguage = dr["language"].ToString();
								this.PageTitle = dr["post_title"].ToString().Trim();
								Item newItem = null;
								if (this.PostType == "quiz") {
									this.CurrentReportType = GetQuizType(this.CurrentPostID);
									if (CurrentReportType == AssessmentQuizType) {
										assessment++;
										this.ArticleItemName = string.Format("Assessment Quiz-{0}", assessment);
										this.Template_Import = "/sitecore/templates/User Defined/Poses/Folders/Assessment Quiz Folder";
										newItem = this.CreateItem(SetImportConfiguration());
									}
									else {
										knowledge++;
										this.ArticleItemName = string.Format("Knowledge Quiz-{0}", knowledge);
										this.Template_Import = "/sitecore/templates/User Defined/Poses/Folders/Knowledge Quiz Folder";
										newItem = this.CreateItem(SetImportConfiguration());
									}
									if (newItem != null) {
										this.AddDifferentLanguageVerstion(newItem);
										if (HasChildPost) {
											this.GetChilds(newItem);
										}
									}
								}
								else {
									newItem = this.CreateItem(SetImportConfiguration());

									if (newItem != null) {
										this.AddDifferentLanguageVerstion(newItem);
										if (HasChildPost) {
											this.GetChilds(newItem);
										}
									}
								}
							}
						}
                    }
                }
                Response.Write(this.PostType + "- Record count: " + i + "<br/>");
            }
            ds.Dispose();

        }
Beispiel #30
0
    public Dictionary<int, NowAndNext> GetNowAndNext(List<Channel> aEpgChannelList)
    {
      Dictionary<int, NowAndNext> nowNextList = new Dictionary<int, NowAndNext>();
      string provider = ProviderFactory.GetDefaultProvider().Name.ToLowerInvariant();
      string connectString = ProviderFactory.GetDefaultProvider().ConnectionString;
      MySqlConnection MySQLConnect = null;
      MySqlDataAdapter MySQLAdapter = null;
      MySqlCommand MySQLCmd = null;

      SqlDataAdapter MsSqlAdapter = null;
      SqlConnection MsSqlConnect = null;
      SqlCommand MsSqlCmd = null;

      try
      {
        switch (provider)
        {
          case "mysql":
            MySQLConnect = new MySqlConnection(connectString);
            MySQLAdapter = new MySqlDataAdapter();
            MySQLAdapter.TableMappings.Add("Table", "Program");
            MySQLConnect.Open();
            MySQLCmd = new MySqlCommand(BuildCommandTextMiniGuide(provider, aEpgChannelList), MySQLConnect);
            MySQLAdapter.SelectCommand = MySQLCmd;
            break;
          case "sqlserver":
            //MSSQLConnect = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;" + connectString);
            MsSqlConnect = new SqlConnection(connectString);
            MsSqlAdapter = new SqlDataAdapter();
            MsSqlAdapter.TableMappings.Add("Table", "Program");
            MsSqlConnect.Open();
            MsSqlCmd = new SqlCommand(BuildCommandTextMiniGuide(provider, aEpgChannelList), MsSqlConnect);
            MsSqlAdapter.SelectCommand = MsSqlCmd;
            break;
          default:
            //MSSQLConnect = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;" + connectString);
            Log.Info("BusinessLayer: No connect info for provider {0} - aborting", provider);
            return nowNextList;
        }

        using (DataSet dataSet = new DataSet("Program"))
        {
          // ToDo: check if column fetching wastes performance
          switch (provider)
          {
            case "sqlserver":
              if (MsSqlAdapter != null)
              {
                MsSqlAdapter.Fill(dataSet);
              }
              break;
            case "mysql":
              if (MySQLAdapter != null)
              {
                MySQLAdapter.Fill(dataSet);
              }
              break;
          }

          nowNextList = BuildNowNextFromDataSet(dataSet);
        }
      }
      catch (Exception ex)
      {
        Log.Info("BusinessLayer: GetNowNext failed {0}", ex.Message);
      }
      finally
      {
        switch (provider)
        {
          case "mysql":
            if (MySQLConnect != null)
            {
              MySQLConnect.Close();
            }
            if (MySQLAdapter != null)
            {
              MySQLAdapter.Dispose();
            }
            if (MySQLCmd != null)
            {
              MySQLCmd.Dispose();
            }
            if (MySQLConnect != null)
            {
              MySQLConnect.Dispose();
            }
            break;
          case "sqlserver":
            if (MsSqlConnect != null)
            {
              MsSqlConnect.Close();
            }
            if (MsSqlAdapter != null)
            {
              MsSqlAdapter.Dispose();
            }
            if (MsSqlCmd != null)
            {
              MsSqlCmd.Dispose();
            }
            if (MsSqlConnect != null)
            {
              MsSqlConnect.Dispose();
            }
            break;
        }
      }
      return nowNextList;
    }
        private void GetChilds(Item newItem) {
            DataSet ds = new DataSet();
            Dictionary<string, string> fields = new Dictionary<string, string>();

            using (MySqlConnection connection = new MySqlConnection(MyConnectionString)) {
                MySqlCommand cmd = connection.CreateCommand();
                string getPostQuery = string.Empty;

                getPostQuery = "SELECT wp1.post_id as 'PostID', wp.post_type " +
                                       "FROM wp_posts wp " +
                                       "INNER JOIN wp_postmeta wp1 ON wp.ID = wp1.post_id " +
                                       "WHERE wp1.meta_key = '" + this.BelongTo + "' AND wp1.meta_value = '" + this.DefaultLanguagePostID + "' ";

                connection.Open();
                cmd.CommandTimeout = 99999;

                cmd.CommandText = getPostQuery;
                MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
                adap.Fill(ds);
                cmd.Dispose();
                adap.Dispose();
                connection.Close();
            }

            if (ds != null && ds.Tables.Count > 0) {
                DataTable datasource = ds.Tables[0];
                if (this.PostType == "quiz") {
                    CreateQuestionAnswer(datasource, newItem);
                }
                else {
                    if (datasource != null && datasource.Rows.Count > 0) {
                        foreach (DataRow dr in datasource.Rows) {
                            this.PostType = dr["post_type"].ToString();
                            SetImportConfiguration();
                            this.ChildPostID = dr["PostID"].ToString();
                            AddChilds(newItem);
                        }
                    }
                    this.PostType = this.NextPostType;

                }
            }
            ds.Dispose();

        }