Exemplo n.º 1
0
        /// <summary>
        /// 全部导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AllExportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OleDbConnection oc = GlobalInfo.GlobalConnection;

            oc.Open();
            string           sql  = "select topic as 会议主题,department as 办会部门,creater as 办会人, createtime as 会议开始时间, endtime as 会议结束时间,uuid as 标识 from meetingtable";
            OleDbCommand     ocmd = new OleDbCommand(sql, oc);
            OleDbDataAdapter oda  = new OleDbDataAdapter(ocmd);
            DataTable        dt   = new DataTable("meetinghistory");

            oda.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("未查到有效数据!");
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = readValueFromConfigByNode("backup").ToString() == "0"?"(*.xml)|*.xml":"(*.xls)|*.xls";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(sfd.FileName))
                {
                    DialogResult dr = MessageBox.Show("文件已存在,是否覆盖?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dr == DialogResult.Yes)
                    {
                        File.Delete(sfd.FileName);//先删除
                    }
                    else
                    {
                        return;
                    }
                }
                if (readValueFromConfigByNode("backup").ToString() == "0")
                {
                    GlobalInfo.DataTableToXml(dt, sfd.FileName);
                }
                else
                {
                    GlobalInfo.DataTableToExcel(dt, sfd.FileName);
                }
                MessageBox.Show("导出完毕!", "提示!");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okBtn_Click(object sender, EventArgs e)
        {
            OleDbConnection oc = GlobalInfo.GlobalConnection;

            oc.Open();
            //根据条件进行添加
            string createTimeStr  = "";
            bool   createTimeFlag = false;
            string topicStr       = "";
            string departStr      = "";
            string createrStr     = "";

            if (radioButton2.Checked)
            {
                if (dateTimePicker2.Value < dateTimePicker1.Value)
                {
                    MessageBox.Show("时间配置错误,结束时间不能小于开始时间!");
                    return;
                }
                createTimeStr  = " and createtime>@time1 and createtime<@time2 ";
                createTimeFlag = true;
            }
            if (radioButton4.Checked)
            {
                if (topicKey.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("请输入关键字!");
                    return;
                }
                string[] tmp  = topicKey.Text.Trim().Split(';');//使用中文分号
                string   list = "";
                foreach (string str in tmp)
                {
                    list = list + "topic like '%" + str + "%'" + " or ";
                }
                list     = "(" + list.Substring(0, list.Length - 3) + ")";
                topicStr = " and " + list;
            }
            if (radioButton6.Checked)
            {
                if (depart.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("请输入关键字!");
                    return;
                }
                string[] tmp  = depart.Text.Trim().Split(';');
                string   list = "";
                foreach (string str in tmp)
                {
                    list = list + "department like '%" + str + "%'" + " or ";
                }
                list      = "(" + list.Substring(0, list.Length - 3) + ")";
                departStr = " and " + list;
            }
            if (radioButton8.Checked)
            {
                if (creater.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("请输入关键字!");
                    return;
                }
                string[] tmp  = creater.Text.Trim().Split(';');
                string   list = "";
                foreach (string str in tmp)
                {
                    list = list + "creater like '%" + str + "%'" + " or ";
                }
                list       = "(" + list.Substring(0, list.Length - 3) + ")";
                createrStr = " and " + list;
            }

            string       sql  = "select topic as 会议主题,department as 办会部门,creater as 办会人, createtime as 会议开始时间, endtime as 会议结束时间,uuid as 标识 from meetingtable where 1=1 " + createTimeStr + topicStr + departStr + createrStr;
            OleDbCommand ocmd = new OleDbCommand(sql, oc);

            if (createTimeFlag)
            {
                ocmd.Parameters.Add("time1", OleDbType.Date);
                ocmd.Parameters.Add("time2", OleDbType.Date);
                ocmd.Parameters["time1"].Value = dateTimePicker1.Value;
                ocmd.Parameters["time2"].Value = dateTimePicker2.Value;
            }
            OleDbDataAdapter oda = new OleDbDataAdapter(ocmd);
            DataTable        dt  = new DataTable("meetinghistory");

            oda.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("未查到有效数据!");
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = readValueFromConfigByNode("backup").ToString() == "0" ? "(*.xml)|*.xml" : "(*.xls)|*.xls";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(sfd.FileName))
                {
                    DialogResult dr = MessageBox.Show("文件已存在,是否覆盖?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dr == DialogResult.Yes)
                    {
                        File.Delete(sfd.FileName);//先删除
                    }
                    else
                    {
                        return;
                    }
                }
                if (readValueFromConfigByNode("backup").ToString() == "0")
                {
                    GlobalInfo.DataTableToXml(dt, sfd.FileName);
                }
                else
                {
                    GlobalInfo.DataTableToExcel(dt, sfd.FileName);
                }
                MessageBox.Show("导出完毕!", "提示!");
            }
        }