Пример #1
0
        private void refreshRow(DataSet ds, ListDataRow row)
        {
            if (ds.Tables.Count < 1)
            {
                return;
            }
            DataTable tb = ds.Tables[0];

            if (tb.Rows.Count < 1)
            {
                return;
            }

            foreach (DataColumn col in tb.Columns)
            {
                string field = col.ColumnName;
                string fName = XSqlBuilder.OLD_VERSION_PIX + field;

                if (row.ContainsKey(field))
                {
                    row[field] = tb.Rows[0][field].ToString();
                }

                if (row.ContainsKey(fName))
                {
                    row[fName] = tb.Rows[0][field].ToString();
                }
            }
        }
Пример #2
0
        public List <string> getFieldFiles(string field, ListDataRow rowId)
        {
            List <string> ret    = new List <string>();
            string        folder = getRecordFolder(field, rowId);

            string[] files = Directory.GetFiles(folder);
            foreach (string file in files)
            {
                string fileName = getFieldFolder(field) + file;
                ret.Add(getFileUrl(fileName));
            }
            return(ret);
        }
Пример #3
0
        public static ListDataRow readRow(DataTable tb, DataSourceSchema dsSchema, DataRow dRow)
        {
            List <DataListColumn> fColumns = EUGridUtils.getColumns(dsSchema.Fields);

            ListDataRow row = new ListDataRow();

            foreach (DataListColumn dcol in fColumns)

            //                foreach (FieldSchema fldSchema in _schema.Fields)
            //foreach (DataColumn col in tb.Columns)
            {
                string fName = dcol.field;
                if (fName.StartsWith(XSqlBuilder.OLD_VERSION_PIX))
                {
                    fName = fName.Remove(0, XSqlBuilder.OLD_VERSION_PIX.Length);
                }

                if (!dsSchema.Fields.ContainsId(fName))
                {
                    row.Add("ck", "false");
                    continue;
                }
                FieldSchema fldSchema = dsSchema.Fields.GetItem(fName);

                if (fldSchema.DataType == DbType.Binary)
                {
                    continue;
                }

                DataColumn col = tb.Columns[fName];


                //   if (!string.IsNullOrEmpty(fldSchema.Alias))
                //       fName = fldSchema.Alias;
                //if (col == null)
                //    throw new Exception(string.Format(Lang.FieldNotFind, fName));
                string value = "";
                if (col != null)
                {
                    value = GetCellString(fldSchema, col, dRow);
                }
                row.Add(dcol.field, value);

                //      if (tb.PrimaryKey.Contains(col))
                //      {
                // row.Add(dcol, value);
                //row.Pk.Add(fName, value);
                //     }
            }
            return(row);
        }
Пример #4
0
 public static bool isNewRow(ListDataRow row)
 {
     foreach (string fld in row.Keys)
     {
         if (fld.StartsWith(XSqlBuilder.OLD_VERSION_PIX))
         {
             if (!string.IsNullOrEmpty(row[fld]))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #5
0
        public void update(ListDataRow row)
        {
            //if (_isSourceTable)
            //    updateSourceTableRow(row);
            DsAdapterCustomer dbsa = new DsAdapterCustomer(_schema);

            if (DataSourceComm.isNewRow(row))
            {
                dbsa.insert(row, this.getQueryParams(_schema.InsertCommand));
            }
            else
            {
                dbsa.update(row, this.getQueryParams(_schema.UpdateCommand));
            }
        }
Пример #6
0
        public List <ListDataRow> rows()
        {
            List <ListDataRow> ret = new List <ListDataRow>();
            DataSet            ds  = getDataSet();
            DataTable          tb  = ds.Tables[0];

            if (tb == null)
            {
                return(ret);
            }

            int start = 0;
            int count = tb.Rows.Count;


            if (!_pagination.isStoreProcessPagination)
            {
                if (_pagination.page != 0 && _pagination.pageSize != 0)
                {
                    start = (_pagination.page - 1) * _pagination.pageSize;
                    count = (_pagination.page) * _pagination.pageSize;
                }
            }

            if (start < 0)
            {
                start = 0;
            }

            for (int r = start; r < count; r++)
            {
                if (r >= tb.Rows.Count)
                {
                    break;
                }
                DataRow dRow = tb.Rows[r];

                ListDataRow row = DataSourceComm.readRow(tb, _schema, dRow);
                ret.Add(row);
            }

            if (_pagination.isStoreProcessPagination)
            {
                this._ds = null;
            }

            return(ret);
        }
Пример #7
0
 private bool isNewRow(ListDataRow row)
 {
     if (schema.PrimaryKeys == null || schema.PrimaryKeys.Count <= 0)
     {
         throw new XException(Lang.NoMainKey);
     }
     foreach (string pk in _schema.PrimaryKeys)
     {
         string kf = XSqlBuilder.OLD_VERSION_PIX + pk;
         if (!row.ContainsKey(kf) || string.IsNullOrEmpty(row[kf]))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #8
0
 public void executeCommandSchema(CommandSchema commandSchema, ListDataRow row, Dictionary <string, string> realParams, bool refresh = false)
 {
     using (TransactionScope ts = new TransactionScope())
     {
         DbCommand cmd = getCommand(commandSchema);
         setCommandParamValue(cmd, realParams, row);
         if (refresh)
         {
             DataSet ds = dbAdmin.executeDateSet(cmd);
             refreshRow(ds, row);
         }
         else
         {
             dbAdmin.execNonQuery(cmd);
         }
         ts.Complete();
     }
 }
Пример #9
0
        private void updateSubTables(ListDataRow row, List <SubTable> subTables)
        {
            if (subTables == null || subTables.Count < 1)
            {
                return;
            }
            for (int c = 0; c < subTables.Count; c++)
            {
                string           subTable = subTables[c].Name;
                DataSourceSchema ds       = DataSourceSchemaContainer.Instance().GetItem(subTable);
                if (ds.SelectCommand.CommandType != CommandType.TableDirect)
                {
                    throw new XException(string.Format(Lang.SubTableSelCommandTypeOnlyIsTable, subTable));
                }

                SubTableSchema sds = DataSourceComm.getSubTableSchema(subTable, _schema);
                Dictionary <string, string> parametes = new Dictionary <string, string>();


                for (int i = 0; i < sds.Fks.Count; i++)
                {
                    string fk = sds.Fks[i];
                    parametes.Add("@" + fk, row[_schema.PrimaryKeys[i]]);
                }


                DsAdapter dsa = new DsAdapterCustomer(ds);

                List <ListDataRow> subRows = subTables[c].Rows;
                for (int i = 0; i < subRows.Count; i++)
                {
                    ListDataRow subRow = subRows[i];
                    if (DataSourceComm.isNewRow(subRow))
                    {
                        dsa.insert(subRow, parametes);
                    }
                    else
                    {
                        dsa.update(subRow, parametes);
                    }
                }
            }
        }
Пример #10
0
        public ListDataRow row(Dictionary <string, string> pk)
        {
            if (pk == null || pk.Count < 1)
            {
                throw new Exception(Lang.UpdateNoKey);
            }

            StringBuilder sb = new StringBuilder();

            foreach (string field in pk.Keys)
            {
                sb.Append(" and ");
                sb.Append(field);
                sb.Append("='");
                sb.Append(pk[field]);
                sb.Append("' ");
            }

            sb.Remove(0, 5);
            PaginationInfo pagin = new PaginationInfo();

            DsAdapterCustomer dsa = new DsAdapterCustomer(_schema);
            DataSet           ds  = dsa.getDataSet(getQueryParams(_schema.SelectCommand), sb.ToString(), null, null, pagin);

            if (ds.Tables.Count < 1)
            {
                return(null);
            }
            DataTable tb = ds.Tables[0];

            DataRow[] rows = tb.Select(sb.ToString());
            if (tb.Rows.Count < 1)
            {
                return(null);
            }
            ListDataRow ret = DataSourceComm.readRow(tb, _schema, rows[0]);

            return(ret);
        }
Пример #11
0
        private string getRecordFolder(string fieldName, ListDataRow row)
        {
            StringBuilder sb    = new StringBuilder();
            List <string> mkeys = _schema.PrimaryKeys;

            for (int i = 0; i < mkeys.Count; i++)
            {
                string keyName = mkeys[i];
                string keyVal  = row[keyName];
                sb.Append('_');
                sb.Append(keyVal);
            }

            string fFolder = getFieldFolder(fieldName);

            fFolder = fFolder + sb.ToString() + "\\";
            if (!Directory.Exists(fFolder))
            {
                Directory.CreateDirectory(fFolder);
            }
            return(fFolder);
        }
Пример #12
0
        public void form()
        {
            ListDataRow row = new ListDataRow();

            foreach (string fld in this.Request.Form.AllKeys)
            {
                row.Add(fld, Request.Form[fld]);
            }

            for (int i = 0; i < Request.Files.AllKeys.Length; i++)
            {
                string         fld           = Request.Files.AllKeys[i];
                HttpPostedFile file          = Request.Files[i];
                List <string>  updatedFields = new List <string>();


                if (file != null && file.ContentLength > 0)
                {
                    string recFolder = getRecordFolder(fld, row);
                    string fileName  = Path.GetFileName(file.FileName);

                    fileName = recFolder + fileName;
                    file.SaveAs(fileName);

                    if (fld.StartsWith("file_"))
                    {
                        fld = fld.Remove(0, 5);
                    }

                    if (!updatedFields.Contains(fld))
                    {
                        row[fld] = TextType.img + getFileUrl(fileName);
                    }
                }
            }
            update(row);
        }
Пример #13
0
        public void insert(ListDataRow row)
        {
            DsAdapterCustomer dbsa = new DsAdapterCustomer(_schema);

            dbsa.insert(row, getQueryParams(_schema.InsertCommand));
        }
Пример #14
0
        private void setCommandParamValue(DbCommand cmd, Dictionary <string, string> paramValues, ListDataRow row)
        {
            foreach (DbParameter dbp in cmd.Parameters)
            {
                string pName = dbp.ParameterName;
                string fName = pName.Remove(0, 1);
                object value = null;

                if (row != null && row.ContainsKey(fName))
                {
                    if (!string.IsNullOrEmpty(row[fName]))
                    {
                        value = row[fName];
                    }
                }

                if (paramValues != null && paramValues.ContainsKey(pName))
                {
                    if (!string.IsNullOrEmpty(paramValues[pName]))
                    {
                        value = paramValues[pName];
                    }
                }

                dbAdmin.Database.SetParameterValue(cmd, pName, value);
            }
        }
Пример #15
0
 public void update(ListDataRow row, List <SubTable> subTables)
 {
     update(row);
     updateSubTables(row, subTables);
 }
Пример #16
0
 public void update(ListDataRow row, Dictionary <string, string> realParams)
 {
     executeCommandSchema(schema.UpdateCommand, row, realParams, true);
 }
Пример #17
0
 public void updateRow(ListDataRow row)
 {
     update(row);
 }
Пример #18
0
        /// <summary>
        /// 获取过滤表单的输入组件定义
        /// </summary>
        /// <returns></returns>
        private DataSet updateSourceTableRow(ListDataRow row)
        {
            DatabaseAdmin dba = DatabaseAdmin.getInstance(_schema.ConnectionName);
            //            Database db = dba.Database;
            DbCommand cmd = null;

            cmd = dba.getSqlStringCommand(" update " + _schema.TableName);
            StringBuilder sb      = new StringBuilder();
            StringBuilder sbWhere = new StringBuilder();

            sb.Append(" update [");
            sb.Append(_schema.TableName);
            sb.Append("] set ");

            bool first = true;

            foreach (string field in row.Keys)
            {
                string paramName = "@" + field.Replace(' ', '_');


                FieldSchema fldSchema = null;
                if (field.StartsWith(XSqlBuilder.OLD_VERSION_PIX))
                {
                    string keyField = field.Replace(XSqlBuilder.OLD_VERSION_PIX, "");
                    fldSchema = _schema.Fields.GetItem(keyField);
                    sbWhere.Append(" and [");
                    sbWhere.Append(keyField);
                    sbWhere.Append("]=");
                    sbWhere.Append(paramName);
                }
                else
                {
                    fldSchema = _schema.Fields.GetItem(field);

                    if (readOnlyFields.Contains(field))
                    {
                        continue;
                    }

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }

                    sb.Append("[");
                    sb.Append(field);
                    sb.Append("]");
                    sb.Append("=");
                    sb.Append(paramName);
                }

                dba.addInParameter(cmd, paramName, fldSchema.DataType, string.IsNullOrEmpty(row[field]) ? null : row[field]);
            }

            sbWhere.Remove(0, 5);

            if (sbWhere.Length < 2)
            {
                throw new XException(Lang.UpdateNoKey);
            }

            sb.Append(" where ");
            sb.Append(sbWhere.ToString());
            cmd.CommandText = sb.ToString();
            return(dba.executeDateSet(cmd));
        }
Пример #19
0
 public void delete(ListDataRow row, Dictionary <string, string> realParams)
 {
     executeCommandSchema(schema.DeleteCommand, row, realParams);
 }
Пример #20
0
        public void delete(ListDataRow row)
        {
            DsAdapterCustomer dsa = new DsAdapterCustomer(_schema);

            dsa.delete(row, getQueryParams(_schema.DeleteCommand));
        }
Пример #21
0
 public void insert(ListDataRow row, Dictionary <string, string> realParams)
 {
     executeCommandSchema(schema.InsertCommand, row, realParams, true);
 }