Ejemplo n.º 1
0
    private void NodesReSort(string parentPath, string tbl)
    {
        string sqlStr = "SELECT * FROM " + tbl + " ORDER BY fullpath ASC";

        try
        {
            OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
            OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
            OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

            cnn.Open();

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            DataRow dr;

            ocb.QuotePrefix = "[";
            ocb.QuoteSuffix = "]";
            oda.Fill(ds, tbl);

            dt = ds.Tables[tbl];
            int zIndex = -1;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dr = dt.Rows[i];

                if (dr["fullpath"].ToString().Trim() ==  string.Concat(parentPath, "\\", dr["pg"].ToString().Trim()))
                {
                    dr.BeginEdit();
                    dr["zindex"] = ++zIndex;
                    dr.EndEdit();

                    oda.UpdateCommand = ocb.GetUpdateCommand();

                    if (oda.Update(ds, tbl) == 1)
                    {
                        ds.AcceptChanges();
                    }
                    else
                    {
                        ds.RejectChanges();
                    }
                }
            }

            cnn.Close();

            ds.Dispose();
            dt.Dispose();
            ocb.Dispose();
            oda.Dispose();
            cnn.Dispose();

            ds = null;
            ocb = null;
            oda = null;
            dr = null;
            dt = null;
            cnn = null;
        }
        catch
        {
        }
        finally
        {
            tbl = null;
            sqlStr = null;
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 数据库更新方法
 /// </summary>
 /// <param name="l_Ds">数据集</param>
 /// <returns>返回更新行数</returns>
 public int Update(DataSet obj_Ds)
 {
     OleDbCommand l_Command = new OleDbCommand(m_SelectSql, CurrentlyConnection);
     try
     {
         if (this.CurrentlyTransaction != null)
         {
             l_Command.Transaction = CurrentlyTransaction;
         }
         OleDbDataAdapter obj_OleDbDataAdapter = new OleDbDataAdapter();
         obj_OleDbDataAdapter.SelectCommand = l_Command;
         OleDbCommandBuilder l_CommandBuilder = new OleDbCommandBuilder(obj_OleDbDataAdapter);
         try
         {
             return obj_OleDbDataAdapter.Update(obj_Ds, m_TableName);
         }
         finally
         {
             l_CommandBuilder.Dispose();
             obj_OleDbDataAdapter.Dispose();
         }
     }
     finally
     {
         l_Command.Dispose();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes a row from the database.
        /// </summary>
        /// <param name="table">The table in which to delete the row.</param>
        /// <param name="rowKeys">The row ID.</param>
        /// <returns></returns>
        internal static bool DeleteRow(Table table, string rowKeys)
        {
            if (Grid.GotHttpContext &&
                System.IO.File.Exists(String.Format("{0}\\noupdate.webgrid", HttpContext.Current.Server.MapPath("."))) &&
                table.m_Grid.Tag["allowupdate"] == null)
            {
                string content =
                    System.IO.File.ReadAllText(String.Format("{0}\\noupdate.webgrid", HttpContext.Current.Server.MapPath(".")));
                table.m_Grid.SystemMessage.Add(
                    String.IsNullOrEmpty(content)
                        ? "Inserting, updating, or deleting a database record functionality has been disabled."
                        : content);
                return false;
            }
            table.GetData(false);
            if (table.m_Grid.MasterTable.Rows.Count == 0)
                return true;
            if ( table.DataSource != null || table.m_Grid.MasterTable.Rows[0].DataRow != null)
            {
                string tmpId = table.m_Grid.InternalId;
                table.m_Grid.InternalId = rowKeys;
                table.m_Grid.MasterTable.GetData(true);

                switch (table.DataSourceType)
                {
                    case DataSourceControlType.SqlDataSource:
                    case DataSourceControlType.AccessDataSource:
                        DeleteDataSourceControl(table.m_Grid.MasterTable.Rows[0]);
                        break;
                    case DataSourceControlType.ObjectDataSource:
                        DeleteObjectDataSourceControl(table.m_Grid.MasterTable.Rows[0]);
                        break;
                }

                if (table.m_XmlDataDocument == null)
                {
                    table.m_Grid.MasterTable.Rows[0].DataRow.Delete();

                    if ( table.DataSource != null &&  table.DataSource is OleDbDataAdapter)
                    {
                        try
                        {
                            OleDbCommandBuilder updateCommand =
                                new OleDbCommandBuilder((OleDbDataAdapter) table.DataSource);

                            ((OleDbDataAdapter) table.DataSource).Update(
                                table.m_Grid.MasterTable.Rows[0].DataRow.Table);
                            updateCommand.Dispose();
                        }
                        catch (Exception ee)
                        {
                            throw new GridException("Error deleting record from data source.", ee);
                        }
                    }
                    table.m_Grid.MasterTable.Rows[0].DataRow.Table.AcceptChanges();
                }
                else if (table.m_XmlDataDocument != null)
                {

                    try
                    {
                        List<Column> datacolumns = table.Columns.Primarykeys;

                        if (datacolumns == null)
                        {
                            table.m_Grid.SystemMessage.Add("Primary key is required for the XML file to delete rows.",
                                                           true);
                            return false;
                        }

                        foreach (DataTable dt in table.m_XmlDataSet.Tables)
                        {
                            if (dt.TableName != rowKeys) continue;
                            int count = dt.Rows.Count;
                            for (int i = 0; i < count; i++)
                                table.m_XmlDataSet.Tables[dt.TableName].Rows.RemoveAt(0);
                            break;
                        }
                        table.m_XmlDataSet.AcceptChanges();
                        table.m_XmlDataSet.WriteXml(table.m_XmlDataDocument);
                    }
                    catch (Exception ee)
                    {
                        throw new GridDataSourceException("Error removing row in XML", ee);
                    }
                }

                table.m_Grid.InternalId = tmpId;

            }
            else
            {
                string datasourcetable = table.DataSourceId;
                if( datasourcetable == null)
                    return true;
                if (datasourcetable.Equals(Grid.DATASOURCEID_NULL))
                    datasourcetable = table.Columns.Primarykeys[0].DataSourceId ??
                                      table.Columns.Primarykeys[0].DefaultDataSourceId;
                InsertUpdate delete = new InsertUpdate(datasourcetable, QueryType.Delete, table.ConnectionString)
                                          {FilterExpression = BuildPKFilter(table, rowKeys, true)};

                if (table.m_Grid.Debug)
                    table.m_Grid.m_DebugString.AppendFormat("<b>{0}: SqlConnection/OleDB.DeleteRow({1}) </b>- {2}<br/>",
                                                            table.m_Grid.ID, table.DataSourceId, delete.GenerateSql());

                try
                {
                    // MUST FIX;
                    delete.Execute();
                }
                catch (Exception ee)
                {
                    throw new GridDataSourceException(String.Format("Error deleting datasource record (SQL generated:{0}) FILTER: " + BuildPKFilter(table, rowKeys, true), delete.GenerateSql()), ee);
                }
            }

            return true;
        }
Ejemplo n.º 4
0
        public static void CleanTable(string tbl, string cnnStr)
        {
            try
            {
                string sqlStr = "SELECT * FROM " + tbl;

                OleDbConnection cnn = new OleDbConnection(cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();

                oda.Fill(ds, tbl);
                dt = ds.Tables[tbl];

                foreach (DataRow dr in dt.Rows)
                    dr.Delete();

                oda.DeleteCommand = ocb.GetDeleteCommand();

                if (oda.Update(ds, tbl) == 1)
                    ds.AcceptChanges();
                else
                    ds.RejectChanges();

                cnn.Close();

                dt.Dispose();
                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                dt = null;
                ds = null;
                ocb = null;
                oda = null;
                cnn = null;

                sqlStr = null;
            }
            catch
            {
            }
            finally
            {
            }
        }
Ejemplo n.º 5
0
        private void ImportEBook(ref DIConnection Connection, ref DIQueries queries, string languageCode, DITables sourceTableNames, DITables targetTableNames)
        {
            string SqlString = string.Empty;
            string TablePrefix = this._TargetDBConnection.DIDataSetDefault();

            DataTable SourceTopicTable = null;
            string TargetConnectionString = this._TargetDBConnection.GetConnection().ConnectionString;
            string SourceConnectionString = Connection.GetConnection().ConnectionString;
            string SourceDBName = Connection.ConnectionStringParameters.DbName;
            string TargetDBName = this._TargetDBConnection.ConnectionStringParameters.DbName;
            OleDbCommand InsertCommand;
            OleDbDataAdapter Adapter;
            OleDbCommandBuilder CmdBuilder;
            DataSet EbookDataset;
            DataRow Row;
            try
            {
                this._TargetDBConnection.ExecuteNonQuery(AssistantQueries.DeleteFrmEBook(targetTableNames.AssistanteBook));

                // get record from source database
                SourceTopicTable = Connection.ExecuteDataTable(" Select * from " + sourceTableNames.AssistanteBook);

                if (SourceTopicTable.Rows.Count > 0)
                {
                                       //dispose target and source connection
                    this._TargetDBConnection.Dispose();
                    Connection.Dispose();

                    InsertCommand = new OleDbCommand();
                    InsertCommand.Connection = new OleDbConnection(TargetConnectionString);

                    Adapter = new OleDbDataAdapter("Select * from  " + sourceTableNames.AssistanteBook, TargetConnectionString);

                    CmdBuilder = new OleDbCommandBuilder(Adapter);

                    EbookDataset = new DataSet(sourceTableNames.AssistanteBook);
                    Adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                    Adapter.Fill(EbookDataset, targetTableNames.AssistanteBook);         //Fill data adapter
                    Row = EbookDataset.Tables[0].NewRow();

                    try
                    {
                        Row[Assistant_eBook.EBook] = SourceTopicTable.Rows[0][Assistant_eBook.EBook]; //ShpBuffer
                        EbookDataset.Tables[0].Rows.Add(Row);
                        Adapter.Update(EbookDataset, targetTableNames.AssistanteBook);              // Save changes to the database
                    }
                    catch (Exception ex)
                    {
                        ExceptionHandler.ExceptionFacade.ThrowException(ex);
                    }

                    if (CmdBuilder != null)
                    {
                        CmdBuilder.Dispose();
                        CmdBuilder = null;
                    }

                    if (InsertCommand != null)
                    {
                        InsertCommand.Dispose();
                        InsertCommand = null;
                    }
                    if (Adapter != null)
                    {
                        Adapter.Dispose();
                        Adapter = null;
                    }

                    //reconnect the source and target database
                    this._TargetDBConnection = new DIConnection(new DIConnectionDetails(DIServerType.MsAccess,
                         string.Empty, string.Empty, TargetDBName, string.Empty, Common.Constants.DBPassword));
                    Connection = new DIConnection(SourceConnectionString, DIServerType.MsAccess);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.ExceptionFacade.ThrowException(ex);
            }
            finally
            {
                if (SourceTopicTable != null)
                {
                    SourceTopicTable.Dispose();
                }
            }
        }
Ejemplo n.º 6
0
    private bool CleanTable(string tbl)
    {
        bool success = true;

        try
        {
            string sqlStr = "SELECT * FROM " + tbl;

            OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
            OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
            OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

            cnn.Open();

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();

            oda.Fill(ds, tbl);
            dt = ds.Tables[tbl];

            foreach (DataRow dr in dt.Rows)
                dr.Delete();

            oda.DeleteCommand = ocb.GetDeleteCommand();

            if (oda.Update(ds, tbl) == 1)
                ds.AcceptChanges();
            else
                ds.RejectChanges();

            cnn.Close();

            dt.Dispose();
            ds.Dispose();
            ocb.Dispose();
            oda.Dispose();
            cnn.Dispose();

            dt = null;
            ds = null;
            ocb = null;
            oda = null;
            cnn = null;

            sqlStr = null;
        }
        catch
        {
            success = false;
        }
        finally
        {
        }

        return success;
    }
Ejemplo n.º 7
0
    public string NodesAdd(string node, string parent, string fullPath, int zIndex, string tbl, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            node = node.Trim();
            parent = parent.Trim();
            fullPath = fullPath.Trim();
            tbl = tbl.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;

                while (drr.Read())
                {
                    if (drr["fullpath"].ToString().Trim() == fullPath)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    dt = ds.Tables[tbl];
                    dr = dt.NewRow();

                    dr["pg"] = node.Trim();
                    dr["parent"] = parent.Trim();
                    dr["fullpath"] = fullPath.Trim();
                    dr["zindex"] = zIndex;
                    dr["body"] = EncDec.Encrypt("&nbsp;", Base.hashKey);
                    if (parent != "root")
                        dr["viewcount"] = 0;
                    else
                        dr["viewcount"] = -1;

                    dt.Rows.Add(dr);

                    oda.InsertCommand = ocb.GetInsertCommand();

                    if (oda.Update(ds, tbl) == 1)
                    {
                        ds.AcceptChanges();
                        msg = "Added";
                    }
                    else
                    {
                        ds.RejectChanges();
                        msg = "Rejected";
                    }
                }
                else
                    msg = "Already Exist";

                cnn.Close();
                drr.Close();

                ds.Dispose();
                dt.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }

        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 8
0
    public string MasterSetDaysLeft(string count, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim())
        {
            string tbl = "admin";
            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);
                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                cnn.Open();
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables["admin"];
                dr = dt.Rows[0];
                dr.BeginEdit();
                dr["daysleft"] = EncDec.Encrypt(count.Trim(), Base.hashKey);
                dr.EndEdit();

                oda.UpdateCommand = ocb.GetUpdateCommand();

                if (oda.Update(ds, tbl) == 1)
                {
                    ds.AcceptChanges();
                    msg = "Days Count Was Set!";
                }
                else
                {
                    ds.RejectChanges();
                    msg = "Rejected";
                }

                drr.Close();
                cnn.Close();

                cmd.Dispose();
                drr.Dispose();
                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                cmd = null;
                drr = null;
                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 9
0
    public string NewsAdd(string tbl, string title, byte[] zipContents, byte[] buffer, string ext, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            tbl = tbl.Trim();
            title = title.Trim();
            string body = Zipper.DecompressToStrng(zipContents).Trim();
            ext = ext.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables[tbl];
                dr = dt.NewRow();
                int id = dt.Rows.Count + 1;

                if (buffer.Length > 0)
                {
                    //msg = CatchImages("{" + tbl + "}/{" + id + "}", new byte[][] { buffer }, new string[] { ext }, true);
                    msg = CatchImages(tbl , new byte[][] { buffer }, new string[] { ext }, true);
                    if (msg != "Created")
                        return msg;

                    dr["pic"] = pgImages[0];
                }

                dr["id"] = id;
                dr["header"] = EncDec.Encrypt(title.Trim(), Base.hashKey);
                dr["body"] = EncDec.Encrypt(body.Trim(), Base.hashKey);
                dr["archived"] = false;

                string date = string.Empty;

                if (tbl == "newsfa")
                    date = Base.GetPersianDate();
                else if (tbl == "newsen")
                    date = Base.GetGregorianDate();
                else if (tbl == "newsar")
                    date = Base.GetHijriDate();

                dr["date"] = Base.FormatDateToRaw(date);

                dt.Rows.Add(dr);

                oda.InsertCommand = ocb.GetInsertCommand();

                if (oda.Update(ds, tbl) == 1)
                {
                    ds.AcceptChanges();
                    msg = "Added";
                }
                else
                {
                    ds.RejectChanges();
                    msg = "Rejected";
                }

                cnn.Close();
                drr.Close();

                ds.Dispose();
                dt.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }

        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 10
0
    private string ReNewPageImages(string fullPath, string newFullPath)
    {
        string msg = "ReNewed";

        try
        {
            while (true)
            {
                string tbl = "pics";
                string sqlStr = "SELECT * FROM " + tbl;

                OleDbConnection cnn = new OleDbConnection(Base.cnnStrPics);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables[tbl];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];

                    if ((dr["location"].ToString().Trim()).Contains(fullPath))
                    {
                        dr.BeginEdit();
                        dr["location"] = dr["location"].ToString().Trim().Replace(fullPath, newFullPath);
                        dr.EndEdit();

                        oda.UpdateCommand= ocb.GetUpdateCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();
                            msg = "ReNewed";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                            break;
                        }
                    }
                }

                cnn.Close();

                ds.Dispose();
                dt.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;

                break;
            }
        }
        catch (Exception ex)
        {
            msg = ex.Message;
        }
        finally
        {
        }

        return msg;
    }
Ejemplo n.º 11
0
    public string ContactListCatchChanges(string tbl, DataTable dtList, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && IsDaysLeft())
        {
            try
            {
                string sqlStr = "SELECT * FROM " + tbl;

                if (!CleanTable(tbl))
                {
                    return "Can't Clean Table";
                }

                DataRow drList;

                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                oda.Fill(ds, tbl);
                dt = ds.Tables[tbl];

                if (dtList.Rows.Count > 0)
                {
                    for (int i = 0; i < dtList.Rows.Count; i++)
                    {
                        dr = dt.NewRow();
                        drList = dtList.Rows[i];

                        dr["mailbox"] = EncDec.Encrypt(drList[0].ToString().Trim(), Base.hashKey);
                        dr["rname"] = EncDec.Encrypt(drList[1].ToString().Trim(), Base.hashKey);

                        dt.Rows.Add(dr);

                        oda.InsertCommand = ocb.GetInsertCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();
                            msg = "Catched";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                        }
                    }
                }
                else
                    msg = "Catched";

                cnn.Close();

                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                dr = null;
                dt = null;
                ds = null;
                ocb = null;
                oda = null;
                cnn = null;

                tbl = null;
                sqlStr = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
            }
        }
        else
            msg = "illegal";

        return msg;
    }
Ejemplo n.º 12
0
    private string RemoveImages(string[] ids)
    {
        string msg = string.Empty;

        try
        {
            while (true)
            {
                string tbl = "pics";
                string sqlStr = "SELECT * FROM " + tbl;

                OleDbConnection cnn = new OleDbConnection(Base.cnnStrPics);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables[tbl];

                foreach (string id in ids)
                {
                    bool found = false;

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dr = dt.Rows[i];

                        if (dr["id"].ToString().Trim() == id.Trim())
                        {
                            found = true;

                            dr.Delete();
                        }
                    }

                    if (found)
                    {
                        oda.DeleteCommand = ocb.GetDeleteCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();

                            msg = "Removed";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                            break;
                        }
                    }
                    else
                    {
                        msg = "Image Not Found And Cannot Be Removed...";
                        break;
                    }
                }

                cnn.Close();

                ds.Dispose();
                dt.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;

                break;
            }
        }
        catch (Exception ex)
        {
            msg = ex.Message;
        }
        finally
        {
        }

        return msg;
    }
Ejemplo n.º 13
0
    private string CatchImages(string target, byte[][] buffer, string[] ext, bool retFileNames)
    {
        string msg = string.Empty;

        try
        {
            string tbl = "pics";
            string sqlStr = "SELECT * FROM " + tbl;

            OleDbConnection cnn = new OleDbConnection(Base.cnnStrPics);
            OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
            OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

            cnn.Open();

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            DataRow dr;

            ocb.QuotePrefix = "[";
            ocb.QuoteSuffix = "]";
            oda.Fill(ds, tbl);

            string[] fileName = { };

            dt = ds.Tables[tbl];

            foreach (string e in ext)
            {
                while (true)
                {
                    string name = NameGen();
                    bool found = false;

                    foreach (string f in fileName)
                    {
                        if (f == name)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            dr = dt.Rows[i];

                            if (dr["id"].ToString() == name)
                            {
                                found = true;
                                break;
                            }
                        }
                    }

                    if (!found)
                    {
                        int len = fileName.Length;
                        Array.Resize(ref fileName, len + 1);
                        fileName[len] = name;
                        break;
                    }
                }
            }

            for (int i = 0; i < ext.Length; i++)
            {
                dr = dt.NewRow();

                dr["id"] = fileName[i];
                dr["ext"] = ext[i].ToLower().Trim();
                dr["data"] = Convert.ToBase64String(buffer[i]);
                dr["location"] = target.Trim();

                dt.Rows.Add(dr);

                oda.InsertCommand = ocb.GetInsertCommand();

                if (oda.Update(ds, tbl) == 1)
                {
                    ds.AcceptChanges();
                    msg = "Created";
                }
                else
                {
                    ds.RejectChanges();
                    msg = "Rejected";
                    break;
                }
            }

            if (msg == "Created" && retFileNames)
            {
                Array.Resize(ref pgImages, 0);

                pgImages = fileName;

                //msg = "Created";
            }

            cnn.Close();

            ds.Dispose();
            dt.Dispose();
            ocb.Dispose();
            oda.Dispose();
            cnn.Dispose();

            ds = null;
            ocb = null;
            oda = null;
            dr = null;
            dt = null;
            cnn = null;
        }
        catch (Exception ex)
        {
            msg = ex.Message;
        }
        finally
        {
        }

        return msg;
    }
Ejemplo n.º 14
0
    public string NodesChangeIndex(string fullPath, int newIndex, string besidePath, int oldIndex, string tbl, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            fullPath = fullPath.Trim();
            besidePath = besidePath.Trim();
            tbl = tbl.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";

                oda.Fill(ds, tbl);
                dt = ds.Tables[tbl];

                bool found = false;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];

                    if (dr["fullpath"].ToString().Trim() == fullPath)
                    {
                        dr.BeginEdit();
                        dr["zindex"] = newIndex;
                        dr.EndEdit();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();
                            msg = "ReIndexed";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                            return msg;
                        }

                        found = true;
                        continue;
                    }
                    if (dr["fullpath"].ToString().Trim() == besidePath)
                    {
                        dr.BeginEdit();
                        dr["zindex"] = oldIndex;
                        dr.EndEdit();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();
                            msg = "ReIndexed";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                            return msg;
                        }

                        continue;
                    }
                }

                if (!found)
                    msg = "Not Found";

                cnn.Close();

                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 15
0
    public string GoogleEdit(string mailbox, string newMailbox, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            mailbox = mailbox.Trim();
            newMailbox = newMailbox.Trim();

            string tbl = "google";
            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;
                bool duplicate = false;

                mailbox = EncDec.Encrypt(mailbox, Base.hashKey);
                newMailbox = EncDec.Encrypt(newMailbox, Base.hashKey);

                while (drr.Read())
                {
                    if (drr["mailbox"].ToString().Trim() == mailbox)
                        found = true;
                    else if (drr["mailbox"].ToString().Trim() == newMailbox)
                        duplicate = true;
                }

                if (found && !duplicate)
                {
                    dt = ds.Tables[tbl];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dr = dt.Rows[i];

                        if (dr["mailbox"].ToString().Trim() == mailbox)
                        {
                            dr.BeginEdit();

                            dr["mailbox"] = newMailbox;

                            dr.EndEdit();

                            oda.UpdateCommand = ocb.GetUpdateCommand();

                            if (oda.Update(ds, tbl) == 1)
                            {
                                msg = ReNewPageImages(tbl + "\\" + mailbox, tbl + "\\" + newMailbox);

                                if (msg != "ReNewed")
                                    return msg;

                                ds.AcceptChanges();
                                msg = "Updated";
                            }
                            else
                            {
                                ds.RejectChanges();
                                msg = "Rejected";
                            }

                            break;
                        }
                    }
                }
                else if (duplicate)
                    msg = "Duplicate Error";
                else
                    msg = "Not Found";

                cnn.Close();
                drr.Close();

                ds.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 16
0
    public string NewsSetArchive(string tbl, int wh, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            tbl = tbl.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables[tbl];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];
                    if (Convert.ToInt32(dr["id"]) == wh)
                    {
                        dr.BeginEdit();
                        dr["archived"] = !Convert.ToBoolean(dr["archived"]);
                        dr.EndEdit();
                        break;
                    }
                }
                oda.UpdateCommand = ocb.GetUpdateCommand();

                if (oda.Update(ds, tbl) == 1)
                {
                    ds.AcceptChanges();
                    msg = "Updated";
                }
                else
                {
                    ds.RejectChanges();
                    msg = "Rejected";
                }

                cnn.Close();
                drr.Close();

                ds.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 17
0
    public string GoogleErase(string mailbox, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            mailbox = mailbox.Trim();

            string tbl = "google";
            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;

                dt = ds.Tables[tbl];

                mailbox = EncDec.Encrypt(mailbox, Base.hashKey);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];

                    if (dr["mailbox"].ToString().Trim() == mailbox)
                    {
                        found = true;
                        dr.Delete();

                        oda.DeleteCommand = ocb.GetDeleteCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            msg = CleanPageImages(tbl + "\\" + mailbox);

                            if (msg != "Cleaned")
                                return msg;

                            ds.AcceptChanges();
                            msg = "Erased";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                        }

                        break;
                    }
                }

                if (!found)
                    msg = "Not Found";

                cnn.Close();

                ds.Dispose();
                dt.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 18
0
    public string NewsErase(string tbl, int wh, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && IsDaysLeft())
        {
            tbl = tbl.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;
                bool isDeleted = false;

                dt = ds.Tables[tbl];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];

                    if (isDeleted)
                    {
                        dr.BeginEdit();
                        dr["id"] = i + 1;
                        dr.EndEdit();

                        oda.UpdateCommand = ocb.GetUpdateCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();
                            msg = "Erased";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                            break;
                        }
                    }
                    else if (Convert.ToInt32(dr["id"]) == wh)
                    {
                        found = true;

                        if (dr["pic"].ToString().Trim() != string.Empty)
                        {
                            msg = RemoveImages(new string[] { dr["pic"].ToString().Trim() });
                            if (msg != "Removed")
                                return msg;
                        }

                        dr.Delete();

                        oda.DeleteCommand = ocb.GetDeleteCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();
                            msg = "Erased";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                            break;
                        }

                        dt = ds.Tables[tbl];

                        isDeleted = true;
                        --i;
                    }
                }

                if (!found)
                    msg = "Not Found";

                cnn.Close();

                ds.Dispose();
                dt.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 19
0
    public string PreferencesSet(string tag, string val, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            tag = tag.Trim();
            val = val.Trim();

            string tbl = "preferences";
            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);
                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                cnn.Open();
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables[tbl];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];

                    if (dr["tag"].ToString().Trim() == tag)
                    {
                        dr.BeginEdit();
                        dr["val"] = val;
                        dr.EndEdit();

                        oda.UpdateCommand = ocb.GetUpdateCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            ds.AcceptChanges();
                            msg = "OK";
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                        }
                        
                        break;
                    }
                }

                drr.Close();
                cnn.Close();

                cmd.Dispose();
                drr.Dispose();
                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                cmd = null;
                drr = null;
                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;
            }
            catch(Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }

        return msg;
    }
Ejemplo n.º 20
0
    public string NewsEditSet(string tbl, int wh, string title, byte[] zipContents, string imageMode, byte[] buffer, string ext, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            tbl = tbl.Trim();
            title = title.Trim();
            string body = Zipper.DecompressToStrng(zipContents).Trim();
            ext = ext.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables[tbl];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];
                    if (Convert.ToInt32(dr["id"]) == wh)
                    {
                        dr.BeginEdit();
                        dr["header"] = EncDec.Encrypt(title.Trim(), Base.hashKey);
                        dr["body"] = EncDec.Encrypt(body.Trim(), Base.hashKey);

                        switch (imageMode)
                        {
                            case "old":
                                break;
                            case "clean":
                                if (dr["pic"].ToString().Trim() != string.Empty)
                                {
                                    msg = RemoveImages(new string[] { dr["pic"].ToString().Trim() });
                                    if (msg != "Removed")
                                        return msg;
                                    dr["pic"] = string.Empty;
                                }
                                break;
                            case "new":
                                if (dr["pic"].ToString().Trim() != string.Empty)
                                {
                                    msg = RemoveImages(new string[] { dr["pic"].ToString().Trim() });
                                    if (msg != "Removed")
                                        return msg;
                                    dr["pic"] = string.Empty;
                                }
                                //msg = CatchImages("{" + tbl + "}/{" + wh + "}", new byte[][] { buffer }, new string[] { ext }, true);
                                msg = CatchImages(tbl , new byte[][] { buffer }, new string[] { ext }, true);
                                if (msg != "Created")
                                    return msg;
                                dr["pic"] = pgImages[0];
                                break;
                            default:
                                break;
                        }

                        dr.EndEdit();
                        break;
                    }
                }

                if (oda.Update(ds, tbl) == 1)
                {
                    ds.AcceptChanges();
                    msg = "Updated";
                }
                else
                {
                    ds.RejectChanges();
                    msg = "Rejected";
                }

                cnn.Close();
                drr.Close();

                ds.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }

        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 21
0
        private void GenerateReport(DataTable dtReports)
        {
            Base.CleanTable(Base.tblReports, Base.cnnStrReports);

            try
            {
                DataRow drReports;

                string sqlStr = "SELECT * FROM " + Base.tblReports;

                OleDbConnection cnn = new OleDbConnection(Base.cnnStrReports);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                oda.Fill(ds, Base.tblReports);
                dt = ds.Tables[Base.tblReports];

                for (int i = 0; i < dtReports.Rows.Count; i++)
                {
                    dr = dt.NewRow();
                    drReports = dtReports.Rows[i];
                    dr[0] = drReports[0];
                    dr[1] = drReports[1];
                    dt.Rows.Add(dr);
                }

                oda.DeleteCommand = ocb.GetDeleteCommand();

                if (oda.Update(ds, Base.tblReports) == 1)
                    ds.AcceptChanges();
                else
                    ds.RejectChanges();

                sqlStr = null;

                cnn.Close();

                dt.Dispose();
                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                dr = null;
                dt = null;
                ds = null;
                ocb = null;
                oda = null;
                cnn = null;


                this.Activate();
                rptViewCount.Focus();

                rptViewCount.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.FullPage;

                this.PageRanksTableAdapter.Fill(this.reportsDataSet.PageRanks);
                this.rptViewCount.RefreshReport();


                Base.CleanTable(Base.tblReports, Base.cnnStrReports);
            }
            catch (Exception ex)
            {
                MessageBox.Show(errReport + ex.Message, errReportHeader, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                Base.Loading(this, false);
                return;
            }
            finally
            {
            }
        }
Ejemplo n.º 22
0
    public string AdminPwSet(string pw, string npw, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            string tbl = "admin";
            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);
                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                cnn.Open();
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                while (drr.Read())
                {
                    string tPw = EncDec.Decrypt(drr["pw"].ToString(), Base.hashKey);
                    if (tPw == pw.Trim())
                        msg = "OK";
                    else
                        msg = "invalid";
                    break;
                }

                if (msg == "OK")
                {
                    dt = ds.Tables[tbl];
                    dr = dt.Rows[0];
                    dr.BeginEdit();
                    dr["pw"] = EncDec.Encrypt(npw.Trim(), Base.hashKey);
                    dr.EndEdit();

                    oda.UpdateCommand = ocb.GetUpdateCommand();

                    if (oda.Update(ds, tbl) == 1)
                    {
                        ds.AcceptChanges();
                    }
                    else
                    {
                        ds.RejectChanges();
                        msg = "Rejected";
                    }
                }

                drr.Close();
                cnn.Close();

                cmd.Dispose();
                drr.Dispose();
                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                cmd = null;
                drr = null;
                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 23
0
        public override bool InsertBulkRows(string pSelectSQL, System.Data.Common.DbDataReader pDataReader,  SetGadgetStatusHandler pStatusDelegate = null, CheckForCancellationHandler pCancellationDelegate = null)
        {
            bool result = false;

            System.Data.OleDb.OleDbConnection ConnOle = null;
            System.Data.OleDb.OleDbDataAdapter AdapterOle = null;
            System.Data.OleDb.OleDbCommandBuilder builderOLE = null;
            System.Data.Common.DbCommand cmdOle = null;

            DataSet dataSet = new DataSet();
            DataTable Temp = new DataTable();

            try
            {
                StringBuilder InsertSQL;
                StringBuilder ValueSQL;

                ConnOle = new System.Data.OleDb.OleDbConnection(ConnectionString.Replace(";IMEX=1", ""));
                AdapterOle = new System.Data.OleDb.OleDbDataAdapter(pSelectSQL, ConnOle);
                AdapterOle.FillSchema(dataSet, SchemaType.Source);
                AdapterOle.Fill(Temp);
                builderOLE = new System.Data.OleDb.OleDbCommandBuilder();
                builderOLE.DataAdapter = AdapterOle;

                ConnOle.Open();
                cmdOle = ConnOle.CreateCommand();

                cmdOle.CommandTimeout = 1500;

                int rowCount = 0;
                int skippedRows = 0;
                int totalRows = 0;
                int truncatedCellCount = 0;
                bool numericFieldOverflow = false;

                while (pDataReader.Read())
                {
                    cmdOle = builderOLE.GetInsertCommand();
                    InsertSQL = new StringBuilder();
                    ValueSQL = new StringBuilder();

                    InsertSQL.Append("Insert Into ");
                    InsertSQL.Append(pSelectSQL.Replace("Select * From ", ""));
                    InsertSQL.Append(" (");
                    ValueSQL.Append(" values (");
                    int CheckLength = 0;
                    List<OleDbParameter> ParameterList = new List<OleDbParameter>();
                    foreach (System.Data.OleDb.OleDbParameter param in cmdOle.Parameters)
                    {
                        string FieldName = param.SourceColumn;

                        InsertSQL.Append("[");
                        InsertSQL.Append(FieldName);
                        InsertSQL.Append("],");

                        ValueSQL.Append(param.ParameterName);
                        ValueSQL.Append(",");

                        try
                        {
                            param.Value = pDataReader[FieldName];
                        }
                        catch (Exception ex)
                        {
                            param.Value = DBNull.Value;
                        }
                        ParameterList.Add(param);

                    }
                    InsertSQL.Length = InsertSQL.Length - 1;
                    ValueSQL.Length = ValueSQL.Length - 1;
                    InsertSQL.Append(")");
                    ValueSQL.Append(")");
                    InsertSQL.Append(ValueSQL);

                    cmdOle = null;
                    cmdOle = ConnOle.CreateCommand();
                    cmdOle.CommandText = InsertSQL.ToString();

                    foreach (OleDbParameter param in ParameterList)
                    {
                        DbParameter p2 = cmdOle.CreateParameter();
                        p2.DbType = param.DbType;
                        try
                        {
                            p2.Value = pDataReader[param.SourceColumn];
                            CheckLength = p2.Value.ToString().Length;
                            if (CheckLength > 255)
                            {
                                p2.Value = p2.Value.ToString().Substring(0, 255);
                                truncatedCellCount++;
                            }
                        }
                        catch (Exception ex)
                        {
                            p2.Value = DBNull.Value;
                        }
                        p2.ParameterName = param.ParameterName;

                        cmdOle.Parameters.Add(p2);
                    }

                    try
                    {
                        cmdOle.ExecuteNonQuery();
                        rowCount++;
                    }
                    catch (OleDbException ex)
                    {
                        skippedRows++;
                        if (ex.Message.ToLower().Contains("numeric field overflow"))
                        {
                            numericFieldOverflow = true;
                        }
                        continue;
                    }

                    if (pStatusDelegate != null)
                    {
                        totalRows = rowCount + skippedRows;
                        string messageString = String.Empty;

                        if (skippedRows == 0)
                        {
                            messageString = string.Format(SharedStrings.DASHBOARD_EXPORT_PROGRESS, rowCount.ToString(), totalRows.ToString());
                        }
                        else
                        {
                            messageString = string.Format(SharedStrings.DASHBOARD_EXPORT_PROGRESS_INCLUDE_SKIPPED, rowCount.ToString(), totalRows.ToString(), skippedRows.ToString());
                        }
                        pStatusDelegate.Invoke(messageString, (double)rowCount);
                    }

                    if (pCancellationDelegate != null && pCancellationDelegate.Invoke())
                    {
                        pStatusDelegate.Invoke(string.Format(SharedStrings.DASHBOARD_EXPORT_CANCELLED, rowCount.ToString()));
                        break;
                    }
                }

                if (pStatusDelegate != null)
                {
                    totalRows = rowCount + skippedRows;
                    string messageString = String.Empty;

                    if (skippedRows == 0)
                    {
                        messageString = string.Format(SharedStrings.DASHBOARD_EXPORT_SUCCESS, totalRows.ToString());
                    }
                    else if (skippedRows > 0 && !numericFieldOverflow)
                    {
                        messageString = string.Format(SharedStrings.DASHBOARD_EXPORT_SUCCESS_SOME_SKIPPED, rowCount.ToString(), totalRows.ToString(), skippedRows.ToString());
                    }
                    else if (skippedRows > 0 && numericFieldOverflow)
                    {
                        messageString = string.Format(SharedStrings.DASHBOARD_EXPORT_SUCCESS_SOME_SKIPPED_NUMERIC_FIELD_OVERFLOW, rowCount.ToString(), totalRows.ToString(), skippedRows.ToString());
                    }
                    if (truncatedCellCount > 0)
                    {
                        messageString = messageString + string.Format("; {0} cells truncated to 255 maximum character limit.", truncatedCellCount);
                    }
                    pStatusDelegate.Invoke(messageString);
                }
            }
            //catch (System.Exception ex)
            //{
            //    Logger.Log(DateTime.Now + ":  " + ex.Message);
            //}
            finally
            {
                if (ConnOle != null)
                {
                    ConnOle.Close();
                    ConnOle.Dispose();
                }
                if (AdapterOle != null)
                {
                    AdapterOle.Dispose();
                }
                if (builderOLE != null)
                {
                    builderOLE.Dispose();
                }
                if (cmdOle != null)
                {
                    cmdOle.Dispose();
                }
            }

            result = true;
            return result;
        }
Ejemplo n.º 24
0
    public string CalendarGetBody(string title, string tbl, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            title = title.Trim();
            tbl = tbl.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();

                oda.Fill(ds, tbl);

                bool found = false;

                while (drr.Read())
                {
                    if (EncDec.Decrypt(drr["title"].ToString().Trim(), Base.hashKey).Trim() == title)
                    {
                        msg = srvMsgSuccess + EncDec.Decrypt(drr["body"].ToString().Trim(), Base.hashKey).Trim();
                        found = true;
                        break;
                    }
                }

                if (!found)
                    msg = srvMsgErr + "Not Found";

                cnn.Close();
                drr.Close();

                ds.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = srvMsgErr + ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = srvMsgErr + errInvalidLegal;

        return msg;
    }
Ejemplo n.º 25
0
 /// <summary>
 /// 查询全部数据方法
 /// </summary>
 /// <param name="l_Ds">返回数据集</param>
 /// <returns>返回查询行数</returns>
 public int QueryAll(ref DataSet obj_Ds)
 {
     OleDbDataAdapter obj_OleDbDataAdapter = new OleDbDataAdapter(m_SelectSql, CurrentlyConnection);
     if (this.CurrentlyTransaction != null)
     {
         obj_OleDbDataAdapter.SelectCommand.Transaction = CurrentlyTransaction;
     }
     OleDbCommandBuilder obj_CommandBuilder = new OleDbCommandBuilder(obj_OleDbDataAdapter);
     try
     {
         int inRet = obj_OleDbDataAdapter.Fill(obj_Ds, m_TableName);
         return inRet;
     }
     finally
     {
         obj_CommandBuilder.Dispose();
         obj_OleDbDataAdapter.Dispose();
     }
 }
Ejemplo n.º 26
0
    public string CalendarEdit(string month, string day, string title, string newTitle, string body, string tbl, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            month = month.Trim();
            day = day.Trim();
            title = title.Trim();
            newTitle = newTitle.Trim();
            body = body.Trim();
            tbl = tbl.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;
                bool duplicate = false;

                bool isTitleChanged = title == newTitle ? false : true;

                while (drr.Read())
                {
                    if (EncDec.Decrypt(drr["title"].ToString(), Base.hashKey).Trim() == title)
                        found = true;
                    else if (EncDec.Decrypt(drr["title"].ToString().Trim(), Base.hashKey) == newTitle && isTitleChanged)
                        duplicate = true;

                    if (found && !isTitleChanged)
                    {
                        duplicate = false;
                        break;
                    }
                }

                if (found && !duplicate)
                {
                    dt = ds.Tables[tbl];

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dr = dt.Rows[i];

                        if (EncDec.Decrypt(dr["title"].ToString(), Base.hashKey).Trim() == title)
                        {
                            dr.BeginEdit();

                            dr["month"] = month;
                            dr["day"] = day;
                            if (isTitleChanged)
                                dr["title"] = EncDec.Encrypt(newTitle, Base.hashKey);
                            dr["body"] = EncDec.Encrypt(body, Base.hashKey);

                            dr.EndEdit();

                            oda.UpdateCommand = ocb.GetUpdateCommand();

                            if (oda.Update(ds, tbl) == 1)
                            {
                                ds.AcceptChanges();
                                msg = "Updated";
                            }
                            else
                            {
                                ds.RejectChanges();
                                msg = "Rejected";
                            }

                            break;
                        }
                    }
                }
                else if (duplicate)
                    msg = "Duplicate Error";
                else
                    msg = "Not Found";

                cnn.Close();
                drr.Close();

                ds.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 27
0
        private void SaveProxy()
        {
            string tbl = "proxy";
            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStrLocal);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                dt = ds.Tables[tbl];
                dr = dt.Rows[0];
                dr.BeginEdit();
                dr["useie"] = Base.proxyUseDefault;
                if (Base.proxyUseDefault)
                {
                    dr["addr"] = "{IE}";
                    dr["port"] = "{IE}";
                }
                else
                {
                    dr["addr"] = Base.proxyAddr;
                    dr["port"] = Base.proxyPort;
                }
                dr.EndEdit();

                oda.UpdateCommand = ocb.GetUpdateCommand();

                if (oda.Update(ds, tbl) == 1)
                {
                    ds.AcceptChanges();
                    MessageBox.Show("تنظیمات پراکسی اعمال شد", Base.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    ds.RejectChanges();
                }

                cnn.Close();

                ds.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();
                dt.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(Base.errPrefix + ex.Message, Base.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
Ejemplo n.º 28
0
    public string GoogleAdd(string mailbox, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            mailbox = mailbox.Trim();

            string tbl = "google";
            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;

                mailbox = EncDec.Encrypt(mailbox, Base.hashKey);

                while (drr.Read())
                {
                    if (drr["mailbox"].ToString().Trim() == mailbox)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    dt = ds.Tables[tbl];
                    dr = dt.NewRow();

                    dr["mailbox"] = mailbox;

                    dt.Rows.Add(dr);

                    oda.InsertCommand = ocb.GetInsertCommand();

                    if (oda.Update(ds, tbl) == 1)
                    {
                        ds.AcceptChanges();
                        msg = "Added";
                    }
                    else
                    {
                        ds.RejectChanges();
                        msg = "Rejected";
                    }
                }
                else
                    msg = "Already Exist";

                cnn.Close();
                drr.Close();

                ds.Dispose();
                dt.Dispose();
                cmd.Dispose();
                drr.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cmd = null;
                drr = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }

        }
        else
            msg = errInvalidLegal;

        return msg;
    }
Ejemplo n.º 29
0
        /// <summary>
        /// Updates or inserts a row into the table in the data source.
        /// </summary>
        /// <param name="row">The row to be inserted.</param>
        /// <param name="editIndex">The value of the primary key(s) (the column identifier).</param>
        /// <param name="isInsert">Indicates whether the operation is update or insert.</param>
        /// <returns>The (new) values for the primary key(s).</returns>
        internal static bool InsertUpdateRow(ref string editIndex, Row row, bool isInsert)
        {
            #region Error and permissions checks
            if (Grid.GotHttpContext &&
                System.IO.File.Exists(String.Format("{0}\\noupdate.webgrid", HttpContext.Current.Server.MapPath(".")))
                && row.m_Table.m_Grid.Tag["allowupdate"] == null)
            {
                string content =
                    System.IO.File.ReadAllText(String.Format("{0}\\noupdate.webgrid",
                                                             HttpContext.Current.Server.MapPath(".")));
                row.m_Table.m_Grid.SystemMessage.Add(
                    String.IsNullOrEmpty(content)
                        ? "The capability to insert, update, and delete has been disabled."
                        : content);
                return false;
            }
            if (row.Columns.Primarykeys.Count == 0)
            {
                row.m_Table.m_Grid.SystemMessage.Add(
                    "Your data source is missing primary key(s). This is needed to identify the row you want to update, insert or delete.");
                return false;
            }
            #endregion

            bool identity = false;

            if (row.m_Table == row.m_Table.m_Grid.MasterTable)
                row.m_Table.m_Grid.BeforeValidateEvent(ref row);
            ValidateColumns(row);

            BeforeUpdateInsertEventArgs columnArgs = new BeforeUpdateInsertEventArgs
                                                         {DataSourceId = row.m_Table.DataSourceId};
            if (isInsert)
            {
                columnArgs.m_Insert = true;
                columnArgs.m_EditIndex = null;
            }
            else
            {
                columnArgs.m_Update = true;
                columnArgs.m_EditIndex = editIndex;
            }

            for (int i = 0; i < row.Columns.Count; i++)
            {
              //  row.Columns[i].Row = row;
                CellUpdateInsertArgument ea = new CellUpdateInsertArgument();
                if (isInsert)
                {
                    ea.m_Insert = true;
                    ea.m_Update = false;
                }
                else
                {
                    ea.m_Update = true;
                    ea.m_Insert = false;
                }
                ea.Name = row.Columns[i].ColumnId;
                ea.Column = row.Columns[i];
                ea.PostBackValue = row[ea.Name].PostBackValue;
                ea.Value = row[ea.Name].Value;
                ea.DataSourceValue = row[ea.Name].DataSourceValue;

                if (row.m_Table.m_Grid.Trace.IsTracing)
                    row.m_Table.m_Grid.Trace.Trace(
                        isInsert
                            ? "{0} on insert has value '{1}' and old value was '{2}'"
                            : "{0} on update has value '{1}' and old value was '{2}'", ea.Name,
                        ea.Value,
                        ea.DataSourceValue);

                if (row.Columns[i].IsInDataSource == false || row.Columns[i].ColumnType == ColumnType.SystemColumn)
                    ea.IgnoreChanges = true;
                if (row.Columns[i].Identity)
                {
                    ea.IgnoreChanges = true;
                    identity = true;
                    if (editIndex == null && row[i].Value != null)
                        editIndex = row[i].Value.ToString();
                }
                if (ea.IgnoreChanges == false)
                    columnArgs.AcceptChanges = true;
                columnArgs.Row.Add(ea.Name, ea);
            }

            row.m_Table.m_Grid.BeforeUpdateInsertEvent(columnArgs);

            for (int i = 0; i < row.Columns.Count; i++)
                if (row.Columns[i].ColumnType == ColumnType.Foreignkey == false && row.Columns[i].IsInDataSource &&
                    row.Columns[i].ColumnType == ColumnType.SystemColumn == false)
                    row[row.Columns[i].ColumnId].Value = columnArgs.Row[row.Columns[i].ColumnId].Value;

            if (columnArgs.AcceptChanges == false || row.m_Table.m_Grid.SystemMessage.Count > 0)
                return false;

            if (String.IsNullOrEmpty(row.m_Table.DataSourceId) && row.m_Table.DataSource == null)
                return true; // No datasources.

            InsertUpdate updateColumn = null;
            bool updates = false;
            if ((String.IsNullOrEmpty(row.m_Table.m_Grid.DataSourceId) ||
                 row.m_Table.DataSourceType != DataSourceControlType.InternalDataSource) && isInsert)
            {
                if ( row.m_Table.DataSource is XmlDataDocument == false)
                    row.m_DataRow = row.m_Table.m_DataSourceColumns.NewRow();
                else
                {
                    // Detect if any node has child nodes.
                    XmlDataDocument xmldoc =  row.m_Table.DataSource as XmlDataDocument;

                    if (xmldoc != null && xmldoc.DocumentElement != null)
                    {
                        XmlNodeList nodeList = xmldoc.
                            DocumentElement.SelectNodes(
                            row.m_Table.m_Xmlxpath);
                        if (nodeList != null)
                            foreach (XmlNode xmlNode in nodeList)
                            {
                                DataRow myrow =
                                    ((XmlDataDocument)  row.m_Table.DataSource).GetRowFromElement(
                                        (XmlElement) xmlNode);
                                if (myrow == null)
                                    continue;

                                if (!xmlNode.HasChildNodes) continue;
                                row.m_Table.m_Grid.SystemMessage.Add(
                                    "This Xml node has child nodes and can only be updated or removed from the loaded XML document.");
                                return false;
                            }
                    }
                    else
                        throw new GridException("XmlDataDocument is null or have a invalid root element (DocumentElement is null)");
                    updates = true;
                    row.m_DataRow = row.m_Table.m_DataSourceColumns.NewRow();
                }
            }

            if (row.DataRow == null)
            {
                string datasourcetable = row.m_Table.DataSourceId;
                if (Grid.DATASOURCEID_NULL == datasourcetable)
                    datasourcetable = row.Columns.Primarykeys[0].DataSourceId ?? row.Columns.Primarykeys[0].DefaultDataSourceId;
                updateColumn =
                    new InsertUpdate(datasourcetable, QueryType.Update,
                                     row.m_Table.m_Grid.ActiveConnectionString);
                if (isInsert)
                    updateColumn.QueryType = QueryType.Insert;
                else
                    updateColumn.FilterExpression = BuildPKFilter(row.m_Table, editIndex, true);
            }
            else
            {
                if ( row.m_Table.DataSource is XmlDataDocument && isInsert == false)
                {
                    if (((XmlDataDocument) row.m_Table.DataSource).DocumentElement == null)
                        throw new GridException("Root of your XmlDocument is null" + row.m_Table.DataSource);
                    List<Column> datacolumns = row.m_Table.Columns.Primarykeys;

                    XmlNodeList nodeList = ((XmlDataDocument)row.m_Table.DataSource).DocumentElement.
                        SelectNodes(
                        row.m_Table.m_Xmlxpath);

                    if (nodeList != null)
                        foreach (XmlNode xmlNode in nodeList)
                        {
                            DataRow myrow =
                                ((XmlDataDocument)row.m_Table.DataSource).GetRowFromElement(
                                    (XmlElement) xmlNode);
                            if (myrow == null)
                                continue;

                            if (xmlNode.HasChildNodes)
                            {
                                if (DetectDataSourceRow(row.m_DataRow, myrow, datacolumns))
                                {
                                    row.m_DataRow = myrow;
                                    updates = true;
                                    break;
                                }
                            }
                            else if (DetectDataSourceRow(row.m_DataRow, myrow, datacolumns))
                            {
                                updates = true;
                                row.m_DataRow = myrow;
                                break;
                            }
                        }
                }
            }

            try
            {
                for (int i = 0; i < row.Columns.Count; i++)
                {
                    if (row.Columns[i].IsInDataSource == false || row.Columns[i].ColumnType == ColumnType.SystemColumn ||
                        !String.IsNullOrEmpty(row.Columns[i].DataSourceId) &&
                        row.Columns[i].ColumnType != ColumnType.Foreignkey &&
                        row.Columns[i].DataSourceId.Equals(row.m_Table.DataSourceId) == false)
                        continue;

                    CellUpdateInsertArgument ea = columnArgs.Row[row.Columns[i].ColumnId];

                   if ( ReferenceEquals(Grid.NULLCONSTANT, ea.Value) || ea.Value == null)
                        ea.Value = DBNull.Value;

                    if (row.Columns[i].ColumnType == ColumnType.Foreignkey == false)
                        row.Columns[i].OnUpdateInsert(ea, row[row.Columns[i].ColumnId]);

                    if (row.m_Table.m_Grid.SystemMessage.Count > 0)
                        return false;

                    if (ea.IgnoreChanges || (row.Columns[i].AllowEdit == false &&
                                             (isInsert == false ||
                                              (row.Columns[i].Primarykey == false &&
                                               (row.Columns[i].Required == false &&
                                                row.Columns[i].IsInDataSource == false)))) ||
                        (row.m_Table.m_Grid.DisplayView == DisplayView.Grid &&
                         row.Columns[i].AllowEditInGrid == false) ||
                        (ea.Value == ea.DataSourceValue && isInsert == false))
                    {
                        StringBuilder reason = new StringBuilder();

                        if (ea.IgnoreChanges)
                            reason.Append("ignore");
                        if (isInsert && row.Columns[i].Primarykey == false)
                            reason.Append(" was not primary key on insert");
                        if (row.m_Table.m_Grid.Trace.IsTracing)
                            row.m_Table.m_Grid.Trace.Trace(
                                isInsert
                                    ? "skipping {0} on insert has value '{1}' and old value was '{2}' (reason: {3})"
                                    : "skipping {0} on update has value '{1}' and old value was '{2}' (reason: {3})",
                                ea.Name, ea.Value, ea.DataSourceValue, reason.ToString());

                        continue;
                    }

                    switch (row.Columns[i].ColumnType)
                    {
                        case ColumnType.File:
                        case ColumnType.Image:
                            if (row.Columns[i].IsBlob == false &&
                                row.Columns[i].FileNameColumn != row.Columns[i].ColumnId)
                                continue;
                            if (ea.Parameter != null && row.Columns[i].FileNameColumn != row.Columns[i].ColumnId)
                            {
                                if (row.DataRow == null)
                                    updateColumn.Add(row.Columns[i].ColumnId, (BinaryReader) ea.Parameter);
                                else if (row.DataRow.Table.Columns.Contains(row.Columns[i].ColumnId))
                                    row.DataRow[row.Columns[i].ColumnId] = ea.Parameter;
                            }
                            else if (Grid.GotHttpContext &&row.Columns[i].FileNameColumn == row.Columns[i].ColumnId &&
                                     HttpContext.Current.Session[row[row.Columns[i].ColumnId].CellClientId + "_img"] != null)
                            {
                                object myvalue = HttpContext.Current.Session[row[row.Columns[i].ColumnId].CellClientId + "_img"];
                                if (row.DataRow == null)
                                    updateColumn.Add(row.Columns[i].ColumnId, myvalue);
                                else if (row.DataRow.Table.Columns.Contains(row.Columns[i].ColumnId))
                                    row.DataRow[row.Columns[i].ColumnId] = myvalue;
                            }
                            break;
                        default:
                            if (row.DataRow == null)
                            {
                                if (updateColumn != null)
                                    updateColumn.Add(row.Columns[i].ColumnId, ea.Value);
                            }
                            else if (row.DataRow.Table.Columns.Contains(row.Columns[i].ColumnId))
                                row.DataRow[row.Columns[i].ColumnId] = ea.Value;
                            break;
                    }
                    updates = true;
                }
            }
            catch (Exception ee)
            {
                throw new GridDataSourceException("Error generating update/insert sql", ee);
            }
            if (row.m_Table.m_Grid.Debug && updateColumn != null)
                row.m_Table.m_Grid.m_DebugString.AppendFormat("<b>Datainterface.InsertUpdateRow</b> - {0}<br/>",
                                                              updateColumn.GetQueryString());

            string res = null;
            if (updates)
            {
                try
                {
                    if (row.DataRow == null && row.m_Table.DataSource == null)
                        res = updateColumn.Execute();
                    else
                    {
                        if ( row.m_Table.DataSource != null &&
                             row.m_Table.DataSource is OleDbDataAdapter)
                        {
                            OleDbCommandBuilder updateCommand =
                                new OleDbCommandBuilder((OleDbDataAdapter)  row.m_Table.DataSource);
                            if (isInsert)
                                row.DataRow.Table.Rows.Add(row.DataRow);

                            ((OleDbDataAdapter)  row.m_Table.DataSource).Update(row.DataRow.Table);
                            updateCommand.Dispose();
                        }
                        else if (row.m_Table.m_XmlDataDocument != null)
                        {
                            try
                            {
                                if (isInsert)
                                    row.DataRow.Table.Rows.Add(row.DataRow);
                               row.m_Table.m_XmlDataSet.WriteXml(row.m_Table.m_XmlDataDocument);
                            }
                            catch (Exception ee)
                            {
                                throw new GridDataSourceException("Error processing xml for updating/inserting", ee);
                            }
                        }
                        else
                        {
                            if (isInsert && row.DataRow != null)
                                row.DataRow.Table.Rows.Add(row.DataRow);
                            switch (row.m_Table.DataSourceType)
                            {
                                case DataSourceControlType.SqlDataSource:
                                case DataSourceControlType.AccessDataSource:
                                    UpdateInsertDataSourceControl(row, isInsert);
                                    break;
                                case DataSourceControlType.ObjectDataSource:
                                    UpdateInsertObjectDataSourceControl(row, isInsert);
                                    break;
                                default:
                                    row.m_Table.m_Grid.BindDataSourceSession();
                                    break;
                            }
                        }
                    }
                }
                catch (Exception ee)
                {
                    if (updateColumn != null)
                        throw new GridDataSourceException("Error executing insert/update sql", ee);
                    throw new GridDataSourceException("Error updating data source", ee);
                }
                if (res != null && isInsert)
                {
                    editIndex = res;

                    foreach (Column column in row.m_Table.Columns)
                    {
                        if (!column.Identity)
                            continue;
                        row[column.ColumnId].Value = editIndex;
                        break;
                    }
                }
            }

            for (int i = 0; i < row.Columns.Count; i++)
                if (!String.IsNullOrEmpty(row.Columns[i].DataSourceId) &&
                    row.m_Table.m_Grid[row.Columns[i].ColumnId].ColumnType == ColumnType.Foreignkey == false)
                    row.Columns[i].UpdateInsertColumnDataSourceId(row, columnArgs, editIndex);
            if (identity == false)
                editIndex = row.PrimaryKeyUpdateValues;
            return true;
        }
Ejemplo n.º 30
0
    public string NodesErase(string fullPath, string parentPath, string tbl, string legal)
    {
        string msg = string.Empty;

        if (tLegal == legal.Trim() && isDaysLeft)
        {
            fullPath = fullPath.Trim();
            parentPath = parentPath.Trim();
            tbl = tbl.Trim();

            string sqlStr = "SELECT * FROM " + tbl;

            try
            {
                OleDbConnection cnn = new OleDbConnection(Base.cnnStr);
                OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);

                cnn.Open();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;

                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;

                dt = ds.Tables[tbl];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dr = dt.Rows[i];

                    if ((dr["fullpath"].ToString().Trim() + "\\").Contains(fullPath + "\\"))
                    {
                        found = true;

                        dr.Delete();

                        oda.DeleteCommand = ocb.GetDeleteCommand();

                        if (oda.Update(ds, tbl) == 1)
                        {
                            msg = CleanPageImages(fullPath);

                            if (msg != "Cleaned")
                                return msg;

                            ds.AcceptChanges();
                            msg = "Erased";
                            i--;
                        }
                        else
                        {
                            ds.RejectChanges();
                            msg = "Rejected";
                            break;
                        }
                    }
                }

                if (!found)
                    msg = "Not Found";

                cnn.Close();

                ds.Dispose();
                dt.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                ds = null;
                ocb = null;
                oda = null;
                dr = null;
                dt = null;
                cnn = null;

                NodesReSort(parentPath, tbl);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                tbl = null;
                sqlStr = null;
            }
        }
        else
            msg = errInvalidLegal;

        return msg;
    }