コード例 #1
0
ファイル: TableBLL.cs プロジェクト: AntonWong/cms
        /// <summary>
        /// 提交表单,返回行号
        /// </summary>
        /// <param name="tableId"></param>
        /// <param name="form"></param>
        /// <returns></returns>
        public int SubmitRow(int tableId, NameValueCollection form)
        {
            //table name :cms_form_tableid
            //column name:field_tableid_columnid
            //button name:cms_form_tableid_btn


            StringBuilder sb = new StringBuilder();
            Regex cregex = new Regex("^field_\\d+_(\\d+)$");

            IDictionary<int, string> rowsData = new Dictionary<int, string>();

            foreach (string key in form)
            {
                if (cregex.IsMatch(key))
                {
                    int columnId = int.Parse(cregex.Match(key).Groups[1].Value);
                    //sb.Append("$").Append(columnID.ToString()).Append("=").Append(form[key]);
                    rowsData.Add(columnId, form[key]);
                }
            }

            TableRowData[] rows = new TableRowData[rowsData.Count];

            int i = 0;
            foreach (KeyValuePair<int, string> pair in rowsData)
            {
                rows[i] = new TableRowData
                {
                    Value = pair.Value,
                    Cid = pair.Key
                };
                ++i;
            }


            return dal.CreateRow(tableId, rows);
        }
コード例 #2
0
ファイル: TableDAL.cs プロジェクト: AntonWong/cms
        public int CreateRow(int tableId, TableRowData[] rows)
        {
            DataBaseAccess db = base.db;
            int rowID = 0;
            string date = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

            base.ExecuteNonQuery(
                new SqlQuery(base.OptimizeSQL(SP.Table_CreateRow),
                    new object[,]{
                {"@tableid", tableId},
                {"@submittime",date}
                    }));

            //获取生成的行编号
            rowID = int.Parse(base.ExecuteScalar(new SqlQuery(base.OptimizeSQL(SP.Table_GetLastedRowID))).ToString());

            foreach (TableRowData row in rows)
            {
                var i = rowID;
                base.ExecuteNonQuery(
                     new SqlQuery(base.OptimizeSQL(SP.Table_InsertRowData),
                         new object[,]{
                     {"@rowid", rowID},
                     {"@columnid", row.Cid},
                     {"@value", row.Value}
                         })
                     );

            }
            return rowID;
        }