Example #1
0
        /// <summary>
        /// 添加语句
        /// </summary>
        /// <param name="ds"></param>
        public void AddData(B_TableInfo b_TableInfo)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("\r\n\r\n");
            stringBuilder.Append("\t//------------------------------------------添加------------------------------------------\r\n");
            stringBuilder.Append("\t/// <summary>\r\n");
            stringBuilder.Append($"\t/// 创建人:{Environment.UserName}\r\n");
            stringBuilder.Append($"\t/// 日  期:{DateTime.Now:yyyy.MM.dd HH:mm}\r\n");
            stringBuilder.Append($"\t/// 描  述:添加:add{b_TableInfo.TableName}\r\n");
            stringBuilder.Append("\t/// </summary>\r\n");
            stringBuilder.AppendLine($"\tpublic int add{b_TableInfo.TableName}()");
            stringBuilder.AppendLine("\t{");

            var    proplist = b_TableInfo.Rows.Select(s => $"[{s.RowName}]");
            string props    = string.Join(",", proplist);                        //以逗号分隔的字符串
            string propsAnd = string.Join(",", proplist.Select(s => $"N'{s}'")); //以逗号分隔的字符串

            stringBuilder.AppendLine($"\t\tstring sql = @\"INSERT INTO {b_TableInfo.TableName} ({props})");
            stringBuilder.AppendLine($"\t\tVALUES ({propsAnd})\";\r\n");

            stringBuilder.AppendLine("\t\tSqlParameter[] parameters = new SqlParameter[]{");

            StringBuilder stringBuilderRow = new StringBuilder();

            for (int i = 0; i < b_TableInfo.Rows.Count(); i++)
            {
                B_RowInfo row = b_TableInfo.Rows[i];
                if (i < b_TableInfo.Rows.Count() - 1)
                {
                    stringBuilder.AppendLine($"\t\t\tnew SqlParameter(\"@{row.RowName}\",SqlDbType.{row.RowType.FirstCharToUpper()},{row.RowByteNum}),");
                }
                else
                {
                    stringBuilder.AppendLine($"\t\t\tnew SqlParameter(\"@{row.RowName}\",SqlDbType.{row.RowType.FirstCharToUpper()},{row.RowByteNum})");
                }

                stringBuilderRow.AppendLine($"\t\tparameters[{i}].Value = {b_TableInfo.TableName}.{row.RowName};");
            }
            stringBuilder.AppendLine("\t\t};");
            stringBuilder.AppendLine(stringBuilderRow.ToString());

            stringBuilder.AppendLine("\t\ttry");
            stringBuilder.AppendLine("\t\t{");
            stringBuilder.AppendLine("\t\t\tDbHelperSQL.ExecuteSql(sql, parameters);");
            stringBuilder.AppendLine("\t\t}");
            stringBuilder.AppendLine("\t\tcatch (Exception ex)");
            stringBuilder.AppendLine("\t\t{");
            stringBuilder.AppendLine("\t\t\tthrow ex;");
            stringBuilder.AppendLine("\t\t}");

            if (!string.IsNullOrEmpty(this.mtb_namespace.Text.Trim()))
            {
                stringBuilder.AppendLine("\t}");
            }
            string text = stringBuilder.ToString();

            this.mrtb_content.Text += text;
            this.ChangeColor();
        }
Example #2
0
        /// <summary>
        /// 增删改语句
        /// </summary>
        /// <param name="ds"></param>
        public void AddInsertUpdateDelete(DataSet ds)
        {
            B_TableInfo b_TableInfo = new B_TableInfo();

            if (ds.Tables["entity_table"].Rows.Count == 0)
            {
                this.mrtb_content.Text = @"没有查询结果...";
            }
            else
            {
                b_TableInfo.TableName = ds.Tables["entity_table"].Rows[0][3].ToString();
                b_TableInfo.Rows      = new List <B_RowInfo>();
                for (int i = 0; i < ds.Tables["entity_table"].Rows.Count; i++)
                {
                    B_RowInfo b_RowInfo = new B_RowInfo();
                    b_RowInfo.RowType        = ds.Tables["entity_table"].Rows[i]["TypeName"].ToString();
                    b_RowInfo.RowName        = ds.Tables["entity_table"].Rows[i]["ColName"].ToString();
                    b_RowInfo.RowByteNum     = ds.Tables["entity_table"].Rows[i]["byteNum"].ToString();
                    b_RowInfo.Identification = Convert.ToInt32(ds.Tables["entity_table"].Rows[i]["identification"]);
                    b_TableInfo.Rows.Add(b_RowInfo);
                }
                //添加
                AddData(b_TableInfo);
                //修改
                UpdateDate(b_TableInfo);
                //删除
                DeleteDate(b_TableInfo);
            }
        }
Example #3
0
        /// <summary>
        /// 删除语句
        /// </summary>
        /// <param name="ds"></param>
        public void DeleteDate(B_TableInfo b_TableInfo)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("\r\n\r\n");
            stringBuilder.Append("\t//------------------------------------------删除------------------------------------------\r\n");
            stringBuilder.Append("\t/// <summary>\r\n");
            stringBuilder.Append($"\t/// 创建人:{Environment.UserName}\r\n");
            stringBuilder.Append($"\t/// 日  期:{DateTime.Now:yyyy.MM.dd HH:mm}\r\n");
            stringBuilder.Append($"\t/// 描  述:删除:del{b_TableInfo.TableName}\r\n");
            stringBuilder.Append("\t/// </summary>\r\n");
            stringBuilder.AppendLine($"\tpublic int del{b_TableInfo.TableName}()");
            stringBuilder.AppendLine("\t{");

            List <B_RowInfo> identifyRow = b_TableInfo.Rows.Where(w => w.Identification == 1 ? true : false).ToList();
            var    proplist = identifyRow.Select(s => $"[{s.RowName}]");
            string propsAnd = string.Join(",", proplist.Select(s => $"{s} = N'{s}'")); //以逗号分隔的字符串

            stringBuilder.AppendLine($"\t\tstring sql = @\"DELETE FROM {b_TableInfo.TableName} WHERE {propsAnd}\r\n");

            stringBuilder.AppendLine("\t\tSqlParameter[] parameters = new SqlParameter[]{");

            StringBuilder stringBuilderRow = new StringBuilder();

            for (int i = 0; i < identifyRow.Count(); i++)
            {
                B_RowInfo row = identifyRow[i];
                if (i < b_TableInfo.Rows.Count() - 1)
                {
                    stringBuilder.AppendLine($"\t\t\tnew SqlParameter(\"@{row.RowName}\",SqlDbType.{row.RowType.FirstCharToUpper()},{row.RowByteNum}),");
                }
                else
                {
                    stringBuilder.AppendLine($"\t\t\tnew SqlParameter(\"@{row.RowName}\",SqlDbType.{row.RowType.FirstCharToUpper()},{row.RowByteNum})");
                }

                stringBuilderRow.AppendLine($"\t\tparameters[{i}].Value ={b_TableInfo.TableName}.{row.RowName};");
            }
            stringBuilder.AppendLine("\t\t};");
            stringBuilder.AppendLine(stringBuilderRow.ToString());

            stringBuilder.AppendLine("\t\ttry");
            stringBuilder.AppendLine("\t\t{");
            stringBuilder.AppendLine("\t\t\tDbHelperSQL.ExecuteSql(sql, parameters);");
            stringBuilder.AppendLine("\t\t}");
            stringBuilder.AppendLine("\t\tcatch (Exception ex)");
            stringBuilder.AppendLine("\t\t{");
            stringBuilder.AppendLine("\t\t\tthrow ex;");
            stringBuilder.AppendLine("\t\t}");

            if (!string.IsNullOrEmpty(this.mtb_namespace.Text.Trim()))
            {
                stringBuilder.AppendLine("\t}");
            }
            string text = stringBuilder.ToString();

            this.mrtb_content.Text += text;
            this.ChangeColor();
        }