Example #1
0
        /// <summary>
        /// 作业进程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = (BackgroundWorker)sender;

            try
            {
                string[]         args          = (string[])e.Argument;
                DataTable        dt            = DataDicService.GetDCTableDetailInfo(args[0], args[1]);
                List <TableInfo> listTableInfo = CommonHelper.DetailDT2List(dt, listTableId);

                int type = GetDocType();
                if (type == 0)
                {
                    string strExportPath = txtOutPutPath.Text.Trim() + ".docx";
                    CommonHelper.CreateWord(listTableInfo, strExportPath, bw);
                }
                else if (type == 1)
                {
                    string strExportPath = txtOutPutPath.Text.Trim() + ".html";
                    CommonHelper.CreateHtml(listTableInfo, strExportPath, Properties.Settings.Default.ServerDBName);
                }
                bw.ReportProgress(100, "Complete");
            }
            catch (Exception ex)
            {
                bw.ReportProgress(0, ex.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string strCon = Properties.Settings.Default.ConnectionString;

            if (String.IsNullOrEmpty(strCon))
            {
                MessageBox.Show("请先进行数据库连接配置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            try
            {
                Common.IsCorrectConnection(strCon);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                StringBuilder sb = new StringBuilder();
                //起始日期
                string bgnDate = dtBgnDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
                //截止日期
                string endDate = dtEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
                //过滤表名
                string strTableName = txtTableName.Text;
                //系统名称
                List <string> list = comCheckBoxList1.GetList();


                sb.AppendFormat(" modify_date BETWEEN '{0}' AND '{1}' ", bgnDate, endDate);

                if (!string.IsNullOrEmpty(strTableName))
                {
                    sb.AppendFormat(" AND name IN ('{0}')", strTableName.Replace("'", "''").Replace(",", "','"));
                }

                if (list != null && list.Count > 0)
                {
                    List <SystemInfo> listInfo = CommonHelper.GetConfig();
                    var query = (from p in listInfo
                                 join q in list
                                 on p.SystemName equals q
                                 select p).ToList <SystemInfo>();
                    sb.Append(" AND (");
                    for (int i = 0; i < query.Count; i++)
                    {
                        SystemInfo info = query[i];
                        sb.AppendFormat(" CHARINDEX('{0}',name,0)=1 ", info.TableName);
                        if (i + 1 < query.Count)
                        {
                            sb.Append(" OR ");
                        }
                        else
                        {
                            sb.Append(" ) ");
                        }
                    }
                }

                DataTable dt = DataDicService.GetDCTableInfo(sb.ToString(), strCon);
                treeView1.Nodes.Clear();
                CommonHelper.TreeData_Bind(dt, treeView1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        /// <summary>
        /// 对比修改的表信息
        /// </summary>
        /// <param name="list"></param>
        private bool CompareTable(List <TableInfo> list)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                //2014-06-07修改BUG,没有需要生成的表则不进行表结构对比
                if (list == null || list.Count == 0)
                {
                    return(true);
                }
                if (radioAdd.Checked)
                {
                    foreach (TableInfo t in list)
                    {
                        t.IsUpdate = false;
                    }
                    return(true);
                }
                //修改,自动识别
                else if (radioUpdate.Checked || radioAuto.Checked)
                {
                    string filter = textTableList.Text;
                    if (string.IsNullOrEmpty(textTableList.Text))
                    {
                        foreach (TableInfo t in list)
                        {
                            sb.AppendFormat("{0},", t.Code);
                        }
                        filter = sb.ToString().Substring(0, sb.Length - 1);
                    }
                    DataTable dt = DataDicService.GetTableInfo(filter, Properties.Settings.Default.ConnectionString);
                    foreach (TableInfo t in list)
                    {
                        if (t.ListColumnInfo == null)
                        {
                            continue;
                        }
                        DataRow[] dr = dt.Select(String.Format("table_name='{0}'", t.Code));
                        if (radioAuto.Checked)
                        {
                            //新增
                            if (dr == null || dr.Count() == 0)
                            {
                                //杜冬军2014-11-09修改自动识别模式下判断是否新增表的BUG
                                t.IsUpdate = false;
                                continue;
                            }
                        }
                        //对比新增列
                        var query = from a in t.ListColumnInfo
                                    where !(
                            from c in dr.AsEnumerable()
                            select c.Field <string>("field_name").ToLower()
                            ).Contains(a.Code.ToLower())
                                    select a;
                        t.ListAddColumnInfo = query.ToList <ColumnInfo>();
                        //对比修改数据类型或者长度的列 2014-12-06修改
                        query = from a in t.ListColumnInfo
                                join b in dr.AsEnumerable()
                                on a.Code.ToLower() equals b.Field <string>("field_name").ToLower()
                                    where string.Compare(a.DataTypeStr, Common.GetDataTypeStr(b.Field <string>("date_type"), b.Field <string>("prec"), b.Field <string>("scale")), true) != 0
                                select a;

                        t.ListUpdateColumnInfo = query.ToList <ColumnInfo>();


                        if (radioUpdate.Checked)
                        {
                            //修改
                            if (dr == null || dr.Count() == 0)
                            {
                                t.IsUpdate = true;
                                continue;
                            }
                        }
                        string sid = dr[0]["TableGUID"].ToString();
                        if (!String.IsNullOrEmpty(sid))
                        {
                            t.TableObjectID = sid;
                        }
                        //杜冬军2014-08-26修改,修改模式直接从data_dic中读取表中文名
                        string tempTableName = dr[0]["TableName"].ToString();
                        if (!String.IsNullOrEmpty(tempTableName))
                        {
                            if (tempTableName != t.Name)
                            {
                                if (t.Name == t.Comment)
                                {
                                    t.Comment = tempTableName;
                                }
                                t.Name = tempTableName;
                            }
                        }
                        int Sequence = Convert.ToInt32(dr[0]["field_sequence"]);
                        //重新生成列序号
                        foreach (ColumnInfo info in t.ListAddColumnInfo)
                        {
                            info.Sequence = Sequence;
                            Sequence++;
                        }
                        t.IsUpdate = true;
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                return(false);
            }
        }