Example #1
0
        /// <summary>
        /// 获取用于新增的列的值信息
        /// </summary>
        /// <param name="_dtEditor"></param>
        /// <returns></returns>
        internal static string GetInsertColomnValues(DataTable _dtEditor)
        {
            StringBuilder builder = new StringBuilder();

            bool   _isKeyIdentity = IsKeyIdentity(_dtEditor);
            string _keyColomnName = GetKeyColomnName(_dtEditor);

            for (int i = 0; i < _dtEditor.Rows.Count; i++)
            {
                DataRow _drEditor        = _dtEditor.Rows[i];
                string  _colomnNameLower = CommonMaker.StringMaker(_drEditor["ColumnName"].ToString(), false);

                if (_isKeyIdentity)
                {
                    if (_drEditor["ColumnName"].ToString() == _keyColomnName ||
                        _drEditor["ColumnName"].ToString() == "ModifiedBy" ||
                        _drEditor["ColumnName"].ToString() == "ModifyDate")
                    {
                        continue;
                    }
                    builder.Append("@" + _colomnNameLower);
                }
                else
                {
                    builder.Append("@" + _colomnNameLower);
                }

                if ((i + 1) == _dtEditor.Rows.Count)
                {
                    continue;
                }
                builder.Append(",");
            }

            return(builder.ToString().EndsWith(",")
                ? builder.ToString().Substring(0, builder.ToString().Length - 1)
                : builder.ToString());
        }
Example #2
0
        /// <summary>
        /// 获取并设置初始化列
        /// </summary>
        /// <param name="_dtEditor">受影响的表格</param>
        /// <returns></returns>
        internal static DataRowCollection GetInitColomn(DataTable _dtEditor)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("initcol", typeof(string));
            dt.Columns.Add("defaultValue", typeof(string));
            try
            {
                DataRow[] drs = _dtEditor.Select("cisNull='' or defaultVal<>''");
                if (drs.Length > 0)
                {
                    foreach (DataRow dr in drs)
                    {
                        DataRow drNew = dt.NewRow();
                        drNew["initcol"] = string.Format("this.{0}", dr["ColumnName"]);
                        switch (CommonMaker.GetType(dr["TypeName"].ToString()))
                        {
                        case "Guid":
                            drNew["defaultValue"] = "Guid.NewGuid()";
                            break;

                        case "int":
                            drNew["defaultValue"] = "0";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"]
                                    = dr["defaultVal"].ToString().Replace("((", "").Replace("))", "");
                            }
                            break;

                        case "long":
                            drNew["defaultValue"] = "0";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"]
                                    = dr["defaultVal"].ToString().Replace("((", "").Replace("))", "");
                            }
                            break;

                        case "float":
                            drNew["defaultValue"] = "0";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"]
                                    = dr["defaultVal"].ToString().Replace("((", "").Replace("))", "");
                            }
                            break;

                        case "double":
                            drNew["defaultValue"] = "0";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"]
                                    = dr["defaultVal"].ToString().Replace("((", "").Replace("))", "");
                            }
                            break;

                        case "decimal":
                            drNew["defaultValue"] = "0";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"]
                                    = dr["defaultVal"].ToString().Replace("((", "").Replace("))", "");
                            }
                            break;

                        case "byte":
                            drNew["defaultValue"] = "1";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"]
                                    = dr["defaultVal"].ToString().Replace("((", "").Replace("))", "");
                            }
                            break;

                        case "byte[]":
                            drNew["defaultValue"] = "new byte[]";
                            break;

                        case "string":
                            drNew["defaultValue"] = "string.Empty";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"] =
                                    dr["defaultVal"].ToString().Replace("((", "").Replace("))", "");
                            }
                            break;

                        case "bool":
                            drNew["defaultValue"] = "false";
                            if (!dr["defaultVal"].Equals(""))
                            {
                                drNew["defaultValue"] =
                                    dr["defaultVal"].ToString().Contains("1") ? "true" : "false";
                            }
                            break;

                        case "DateTime":
                            drNew["defaultValue"] = "DateTime.Now";
                            break;

                        default:
                            break;
                        }
                        dt.Rows.Add(drNew);
                    }
                }
                return(dt.Rows);
            }
            catch (Exception ex)
            {
                MessageHelper.ErrorMessageShow("遇到错误:\n\t" + ex.ToString());
                return(null);
            }
        }