Ejemplo n.º 1
0
        public string ConvertTo(object obj)
        {
            if (obj == null)
            {
                return("");
            }

            string             rtn = "";
            UnitDataCollection udc = null;

            if (obj is UnitDataCollection)
            {
                udc = (UnitDataCollection)obj;
            }
            else
            {
                throw new Exception("QueryByPage2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }

            if (udc.QueryTable != null)
            {
                JsonObjectCollection jsonrtn = new JsonObjectCollection();
                //jsonrtn.Add(new JsonStringValue("Count_Of_OnePage", udc.Count_Of_OnePage + ""));
                jsonrtn.Add(new JsonStringValue("page", udc.CurrentPage + ""));
                //jsonrtn.Add(new JsonStringValue("total", udc.TotalPage + ""));
                jsonrtn.Add(new JsonStringValue("total", udc.TotalRow + ""));

                DataTableStd        dts     = udc.QueryTable;
                JsonArrayCollection jsonobj = new JsonArrayCollection("rows");
                for (int j = 0; j < dts.RowLength; j++)
                {
                    JsonObjectCollection jac = new JsonObjectCollection();
                    foreach (string colname in dts.ColumnNames)
                    {
                        if (dts.ColumnDateType(colname).FullName == typeof(DateTime).FullName)
                        {
                            DateTimeStd dtime = DateTimeStd.ParseStd(dts[j, colname]);
                            jac.Add(new JsonStringValue(colname, dtime != null ? dtime.Value.ToString("yyyy/MM/dd HH:mm:ss") : ""));
                        }
                        else
                        {
                            jac.Add(new JsonStringValue(colname, ComFunc.nvl(dts[j, colname])));
                        }
                    }
                    jsonobj.Add(jac);
                }
                jsonrtn.Add(jsonobj);



                rtn = jsonrtn.ToString();
            }

            return(rtn);
        }
Ejemplo n.º 2
0
        public override void Insert(object data, string toTable)
        {
            if (data == null)
            {
                return;
            }
            DataTable todata = null;

            if (data is DataTableStd)
            {
                todata = (DataTableStd)data;
            }
            else if (data is DataTable)
            {
                todata = (DataTable)data;
            }
            else if (data is IEnumerable <object> )
            {
                todata = DataTableStd.ParseStd(data);
            }
            else
            {
                return;
            }

            if (this.sqlconn.State == ConnectionState.Closed)
            {
                this.sqlconn.Open();
            }

            SqlBulkCopy sbc;

            if (this._s == DBStatus.Begin_Trans)
            {
                sbc = new SqlBulkCopy(this.sqlconn, SqlBulkCopyOptions.Default, this.trans);
            }
            else
            {
                sbc = new SqlBulkCopy(this.sqlconn);
            }

            try
            {
                sbc.DestinationTableName = toTable;
                sbc.WriteToServer(todata);
            }
            finally
            {
                sbc.Close();
            }
        }
Ejemplo n.º 3
0
        private bool HasChild(string parentid)
        {
            DataTableStd dtt      = DataTableStd.ParseStd(DataSource);
            DataTableStd dttLevel = dtt.SelectByWhere(ColumnMap_ParentFunctionID + "='" + parentid + "'");

            if (dttLevel.RowLength > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public string ConvertTo(object obj)
        {
            string rtn = "";

            if (obj == null)
            {
                return("");
            }

            DataSet ds = null;

            if (obj is DataSet)
            {
                ds = (DataSetStd)obj;
            }
            else
            {
                throw new Exception("DataSet2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }

            JsonObjectCollection jsonrtn = new JsonObjectCollection();

            for (int i = 0; i < ds.Tables.Count; i++)
            {
                DataTableStd        dts     = DataTableStd.ParseStd(ds.Tables[i]);
                JsonArrayCollection jsonobj = new JsonArrayCollection("TableData" + i);
                for (int j = 0; j < dts.RowLength; j++)
                {
                    JsonObjectCollection jac = new JsonObjectCollection();
                    foreach (string colname in dts.ColumnNames)
                    {
                        if (dts.ColumnDateType(colname).FullName == typeof(DateTime).FullName)
                        {
                            DateTimeStd dtime = DateTimeStd.ParseStd(dts[j, colname]);
                            jac.Add(new JsonStringValue(colname, dtime != null ? dtime.Value.ToString("yyyy/MM/dd HH:mm:ss") : ""));
                        }
                        else
                        {
                            jac.Add(new JsonStringValue(colname, ComFunc.nvl(dts[j, colname])));
                        }
                    }
                    jsonobj.Add(jac);
                }
                jsonrtn.Add(jsonobj);
            }

            rtn = "{" + jsonrtn.ToString() + "}";
            return(rtn);
        }
Ejemplo n.º 5
0
 public void BindData()
 {
     if (DataSource != null)
     {
         DataTableStd dtt = DataTableStd.ParseStd(DataSource);
         for (int i = 0; i < dtt.RowLength; i++)
         {
             int curlevel = IntStd.ParseStd(dtt[i, ColumnMap_FunctionLevel]).Value;
             if (IntStd.ParseStd(dtt[i, ColumnMap_FunctionLevel]) > _maxLevel)
             {
                 _maxLevel = curlevel;
             }
         }
     }
 }
Ejemplo n.º 6
0
        protected void BuildMenu(int level, string parentid, HtmlTextWriter writer)
        {
            DataTableStd dtt = DataTableStd.ParseStd(DataSource);

            string where = ColumnMap_FunctionLevel + "=" + level;
            if (!string.IsNullOrEmpty(parentid))
            {
                where += " AND " + ColumnMap_ParentFunctionID + "='" + parentid + "'";
            }
            DataTableStd dttLevel = dtt.SelectByWhere(where);

            for (int i = 0; i < dttLevel.RowLength; i++)
            {
                string functionid = ComFunc.nvl(dttLevel[i, ColumnMap_FunctionID]);
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "toolbar");
                writer.RenderBeginTag(HtmlTextWriterTag.Li);
                if (ComFunc.nvl(dttLevel[i, ColumnMap_FunctionUrl]) != "")
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, ConvertUrl(ComFunc.nvl(dttLevel[i, ColumnMap_FunctionUrl])));
                    writer.AddAttribute("target", "iFrameRight");
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(ComFunc.nvl(dttLevel[i, ColumnMap_FunctionName]));
                    writer.RenderEndTag();
                }
                else
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:");
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(ComFunc.nvl(dttLevel[i, ColumnMap_FunctionName]));
                    writer.RenderEndTag();
                }

                writer.RenderEndTag();
                //如果含有子菜单
                if (HasChild(functionid))
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Span);
                    //ul
                    writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                    BuildMenu(level + 1, functionid, writer);
                    writer.RenderEndTag();

                    writer.RenderEndTag();
                }
            }
        }
Ejemplo n.º 7
0
        public JsonCollection ConvertTo(object obj)
        {
            if (obj == null)
            {
                return(new JsonObjectCollection());
            }

            DataTableStd dtt = null;

            if (obj is DataTable)
            {
                dtt = DataTableStd.ParseStd(obj);
            }
            else if (obj is DataTableStd)
            {
                dtt = (DataTableStd)obj;
            }
            else
            {
                throw new Exception("DataTable2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }

            JsonArrayCollection jsonobj = new JsonArrayCollection("rows");

            for (int i = 0; i < dtt.RowLength; i++)
            {
                JsonObjectCollection jac = new JsonObjectCollection();
                foreach (string colname in dtt.ColumnNames)
                {
                    if (dtt.ColumnDateType(colname).FullName == typeof(DateTime).FullName)
                    {
                        DateTimeStd dtime = DateTimeStd.ParseStd(dtt[i, colname]);
                        jac.Add(new JsonStringValue(colname, dtime != null ? dtime.Value.ToString("yyyy/MM/dd HH:mm:ss") : ""));
                    }
                    else
                    {
                        jac.Add(new JsonStringValue(colname, ComFunc.nvl(dtt[i, colname])));
                    }
                }
                jsonobj.Add(jac);
            }


            return(jsonobj);
        }
Ejemplo n.º 8
0
        public string ConvertTo(object obj)
        {
            DataTableStd dtt = null;

            if (obj is DataTableStd)
            {
                dtt = (DataTableStd)obj;
            }
            else
            {
                throw new Exception("DataTable2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }
            FrameDLRObject data = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);

            data.SetValue("rows", dtt.Rows);

            return(data.ToJSONString());
        }
Ejemplo n.º 9
0
        public List <E> ConvertTo(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            List <E> rtn = new List <E>();

            DataTableStd dtt = null;

            if (obj is DataTableStd)
            {
                dtt = (DataTableStd)obj;
            }
            else
            {
                throw new Exception("DataTable2List无法转化" + obj.GetType().FullName + "类型数据!");
            }

            Type te = typeof(E);

            if (te == typeof(FrameDLRObject) ||
                te == typeof(object))
            {
                return(dtt.Rows.Select(p => (E)(object)p).ToList());
            }
            else
            {
                PropertyInfo[] pis = te.GetProperties();
                foreach (var item in dtt.Rows)
                {
                    rtn.Add(item.ToModel <E>());
                }
            }

            return(rtn);
        }
Ejemplo n.º 10
0
        protected void BuildLevel1(HtmlTextWriter writer)
        {
            DataTableStd dtt = DataTableStd.ParseStd(DataSource);

            string where = ColumnMap_FunctionLevel + "=1";
            DataTableStd dttLevel   = dtt.SelectByWhere(where);
            int          leve1Index = 0;

            for (int i = 0; i < dttLevel.RowLength; i++)
            {
                string functionid = ComFunc.nvl(dttLevel[i, ColumnMap_FunctionID]);

                writer.AddAttribute(HtmlTextWriterAttribute.Id, "menuLevel1_" + functionid);
                writer.AddAttribute("functionid", functionid);
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "ShowMenu(this," + leve1Index + ");");
                writer.RenderBeginTag(HtmlTextWriterTag.H1);

                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.Write(ComFunc.nvl(dttLevel[i, ColumnMap_FunctionName]));
                writer.RenderEndTag();

                writer.RenderEndTag();

                writer.AddAttribute(HtmlTextWriterAttribute.Class, "no");
                writer.RenderBeginTag(HtmlTextWriterTag.Span);
                //ul
                writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                //如果含有子菜单
                if (HasChild(functionid))
                {
                    BuildMenu(2, functionid, writer);
                }
                writer.RenderEndTag();
                writer.RenderEndTag();

                leve1Index++;
            }
        }
Ejemplo n.º 11
0
        ///将DataTable转换为标准的CSV
        /// </summary>
        /// <param name="table">数据表</param>
        /// <returns>返回标准的CSV</returns>
        private static string DataTableToCsv(DataTableStd table)
        {
            //以半角逗号(即,)作分隔符,列为空也要表达其存在。
            //列内容如存在半角逗号(即,)则用半角引号(即"")将该字段值包含起来。
            //列内容如存在半角引号(即")则应替换成半角双引号("")转义,并用半角引号(即"")将该字段值包含起来。
            StringBuilder sb = new StringBuilder();

            System.Data.DataColumn colum;
            foreach (FrameDLRObject row in table.Rows)
            {
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    colum = table.Columns[i];
                    if (i != 0)
                    {
                        sb.Append(",");
                    }
                    var v = row.GetValue(colum.ColumnName);
                    if (colum.DataType == typeof(string) && row.GetValue(colum.ColumnName).ToString().Contains(","))
                    {
                        sb.Append("\"" + v.ToString().Replace("\"", "\"\"") + "\"");
                    }
                    else if (colum.DataType == typeof(DateTime))
                    {
                        sb.Append(((DateTime)v).ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    }
                    else
                    {
                        sb.Append(v != null ? v.ToString() : "");
                    }
                }
                sb.Append("\r\n");
            }


            return(sb.ToString());
        }
Ejemplo n.º 12
0
        public DataSetStd ConvertTo(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            DataSetStd rtn     = new DataSetStd();
            string     jsonstr = "";

            if (obj is string)
            {
                jsonstr = ComFunc.nvl(obj);
            }
            else
            {
                throw new Exception("Json2DataSet无法转化" + obj.GetType().FullName + "类型数据!");
            }
            JsonReader   reader        = new JsonTextReader(new StringReader(jsonstr));
            string       tablename     = "";
            int          index         = 0;
            bool         isStartArray  = false;
            string       currentColumn = "";
            DataTableStd currentdts    = null;

            while (reader.Read())
            {
                Console.WriteLine(reader.TokenType + "\t\t" + reader.ValueType + "\t\t" + reader.Value);
                if (!isStartArray)
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        tablename = ComFunc.nvl(reader.Value);
                    }
                    if (reader.TokenType == JsonToken.StartArray)
                    {
                        isStartArray = true;
                        currentdts   = new DataTableStd();
                    }
                }
                else
                {
                    //列表数据结束
                    if (reader.TokenType == JsonToken.EndArray)
                    {
                        isStartArray = false;
                        rtn.Tables.Add(currentdts);
                    }
                    //一行资料结束
                    if (reader.TokenType == JsonToken.EndObject)
                    {
                        currentdts.AddNewRow();
                        index++;
                    }

                    //抓取资料栏位
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        if (index == 0)
                        {
                            currentdts.AddColumn(ColumnP.CreatInstanse(ComFunc.nvl(reader.Value)));
                        }
                        currentColumn = ComFunc.nvl(reader.Value);
                    }
                    //抓取资料数据
                    if (reader.TokenType == JsonToken.String ||
                        reader.TokenType == JsonToken.Boolean ||
                        reader.TokenType == JsonToken.Bytes ||
                        reader.TokenType == JsonToken.Date ||
                        reader.TokenType == JsonToken.Float ||
                        reader.TokenType == JsonToken.Integer)
                    {
                        currentdts.SetNewRowValue(reader.Value, currentColumn);
                    }
                }
            }


            return(rtn);
        }
Ejemplo n.º 13
0
        public List <E> ConvertTo(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            List <E> rtn = new List <E>();

            DataTableStd dtt = null;

            if (obj is DataTable)
            {
                dtt = DataTableStd.ParseStd(obj);
            }
            else if (obj is DataTableStd)
            {
                dtt = (DataTableStd)obj;
            }
            else
            {
                throw new Exception("DataTable2List无法转化" + obj.GetType().FullName + "类型数据!");
            }

            Type te = typeof(E);

            PropertyInfo[] pis = te.GetProperties();
            for (int i = 0; i < dtt.RowLength; i++)
            {
                E e = Activator.CreateInstance <E>();

                if (e is FrameDLRObject)
                {
                    var      etemp = (FrameDLRObject)(object)e;
                    string[] cols  = dtt.ColumnNames;
                    foreach (var col in cols)
                    {
                        etemp.SetValue(col, dtt[i, col]);
                    }
                }
                else
                {
                    foreach (PropertyInfo fi in pis)
                    {
                        string   colname = fi.Name;
                        string[] cols    = dtt.ColumnNames;
                        if (cols.Contains <string>(colname, new IgoreCase()))
                        {
                            if (fi.PropertyType.FullName == typeof(bool).FullName)
                            {
                                fi.SetValue(e, dtt[i, colname] == null ? false : dtt[i, colname], null);
                            }
                            else if (fi.PropertyType.FullName == typeof(int).FullName ||
                                     fi.PropertyType.FullName == typeof(float).FullName ||
                                     fi.PropertyType.FullName == typeof(double).FullName ||
                                     fi.PropertyType.FullName == typeof(decimal).FullName)
                            {
                                fi.SetValue(e, dtt[i, colname] == null ? 0 : dtt[i, colname], null);
                            }
                            else if (fi.PropertyType.FullName == typeof(string).FullName)
                            {
                                fi.SetValue(e, ComFunc.nvl(dtt[i, colname]));
                            }
                            else
                            {
                                fi.SetValue(e, dtt[i, colname], null);
                            }
                        }
                    }
                }
                rtn.Add(e);
            }

            return(rtn);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 根据数据集批量删除对应table中的数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="toTable"></param>
        public override void Delete(DataTable data, string toTable)
        {
            if (data == null)
            {
                return;
            }
            string[] keycols = DataTableStd.GetPKName(data);
            string   sql     = "delete from " + toTable;

            string where = "";
            if (keycols.Length <= 0)
            {
                keycols = DataTableStd.GetColumnName(data);
            }

            foreach (string key in keycols)
            {
                if (where == "")
                {
                    where += " where " + key + "=@" + key;
                }
                else
                {
                    where += " and " + key + "=@" + key;
                }
            }

            sql = sql + where;

            SqlCommand tsqlcomm = new SqlCommand("select * from " + toTable + " where 1=0 ", this.sqlconn);

            tsqlcomm.CommandTimeout = 90;


            if (this._s == DBStatus.Begin_Trans)
            {
                tsqlcomm.Transaction = this.trans;
            }

            SqlDataAdapter sda = new SqlDataAdapter(tsqlcomm);
            DataSetStd     ds  = new DataSetStd();

            sda.FillSchema(ds, SchemaType.Source);
            tsqlcomm.CommandText = "SET NOCOUNT ON " + sql;
            sda.DeleteCommand    = tsqlcomm;
            sda.DeleteCommand.Parameters.Clear();
            foreach (string key in keycols)
            {
                DataColumn dc = data.Columns[key];
                sda.DeleteCommand.Parameters.Add("@" + key, ConvertBy(dc.DataType), dc.MaxLength, key);
            }
            sda.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;
            sda.UpdateBatchSize = 0;
            SqlCommandBuilder scb = new SqlCommandBuilder();

            scb.ConflictOption = ConflictOption.OverwriteChanges;
            scb.SetAllValues   = false;
            scb.DataAdapter    = sda;

            DataTableStd dtsdata = DataTableStd.ParseStd(data);

            try
            {
                for (int count = 0; count < dtsdata.RowLength; count++)
                {
                    foreach (string colname in ds[0].ColumnNames)
                    {
                        ds[0].SetNewRowValue(dtsdata[count, colname], colname);
                    }
                    ds[0].AddNewRow();
                    if (((count + 1) % 200 == 0) || ((count + 1) == dtsdata.RowLength))
                    {
                        ds.AcceptChanges();

                        for (int i = 0; i < 200; i++)
                        {
                            if (i >= ds[0].Value.Rows.Count)
                            {
                                break;
                            }

                            ds[0].Value.Rows[i].BeginEdit();
                            ds[0].Value.Rows[i].Delete();
                            ds[0].Value.Rows[i].EndEdit();
                        }
                        sda.Update(ds[0].Value);
                        ds[0].ClearData();
                    }
                }
            }
            finally
            {
                tsqlcomm.Cancel();
                tsqlcomm.Dispose();
                sda.Dispose();
                ds.Dispose();
            }
        }