using System; using System.Collections.Generic; using System.Drawing; using System.Data; using System.Windows.Forms; using IOM_cs.insertForm.service; using IOM_cs.insertForm.service.impl; using IOM_cs.insertForm.data.dto; using System.Reflection; using IOM_cs.insertForm.dtGridView; using IOM_cs.irisDb.service; using IOM_cs.irisDb.service.mySqlImpl; using IOM_cs.irisDb.model; using IOM_cs.irisDb; namespace IOM_cs.insertForm.collection { public partial class CtrlCollectionFrom : UserControl { IIrisCollViewService irisCollViewService = (IIrisCollViewService)DbService.getEntity("IIrisCollViewService"); IUserIrisService iUserIrisService = (IUserIrisService)DbService.getEntity("IUserIrisService"); public static CtrlCollectionFrom ctrlCollectionFrom; IDataSynchService dataSynchService = new DataSynchServiceImpl(); int totalCount = 0; int currentPage = 1; int pageCount = 0; int limitCount = 10; CheckBox ckBox; public CtrlCollectionFrom() { InitializeComponent(); ctrlCollectionFrom = this; comboBoxUpLoad.Items.Add("全部"); comboBoxUpLoad.Items.Add("未上传"); comboBoxUpLoad.Items.Add("已上传"); comboBoxUpLoad.Items.Add("上传失败"); dataGridView1.Rows.Clear(); dataGridView1.BackgroundColor = Color.White; DataGridViewCheckBoxColumn columncb = new DataGridViewCheckBoxColumn(); columncb.HeaderText = ""; columncb.Name = "cb_check"; columncb.TrueValue = true; columncb.FalseValue = false; columncb.DataPropertyName = "IsChecked"; dataGridView1.Columns.Add(columncb); Panel panel = new Panel(); panel.BackColor = Color.White; panel.Size = new System.Drawing.Size(848, 40); panel.Location = new Point(0,0); panel.BackColor = ColorTranslator.FromHtml("#ECEEF2"); dataGridView1.Controls.Add(panel); ckBox = new CheckBox(); ckBox.Text = ""; ckBox.Checked = false; System.Drawing.Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, -1, true); ckBox.Size = new System.Drawing.Size(13, 13); ckBox.BackColor = Color.White; ckBox.Location = new Point(12, 13); ckBox.Click += new EventHandler(ckBox_CheckedChanged); dataGridView1.Controls.Add(ckBox); ckBox.BringToFront(); Label col1 = new Label(); col1.Text = "人员姓名"; col1.Font = new Font("微软雅黑", 10.5f, FontStyle.Bold); col1.ForeColor = ColorTranslator.FromHtml("#333333"); col1.Location = new Point(42, 11); dataGridView1.Controls.Add(col1); col1.BringToFront(); Label col2 = new Label(); col2.Text = "证件类型"; col2.Font = new Font("微软雅黑", 10.5f, FontStyle.Bold); col2.ForeColor = ColorTranslator.FromHtml("#333333"); col2.Location = new Point(121, 11); dataGridView1.Controls.Add(col2); col2.BringToFront(); Label col3 = new Label(); col3.Text = "证件号码"; col3.Font = new Font("微软雅黑", 10.5f, FontStyle.Bold); col3.ForeColor = ColorTranslator.FromHtml("#333333"); col3.Location = new Point(230, 11); dataGridView1.Controls.Add(col3); col3.BringToFront(); Label col4 = new Label(); col4.Text = "户籍地址"; col4.Font = new Font("微软雅黑", 10.5f, FontStyle.Bold); col4.ForeColor = ColorTranslator.FromHtml("#333333"); col4.Location = new Point(392, 11); dataGridView1.Controls.Add(col4); col4.BringToFront(); Label col5 = new Label(); col5.Text = "采集时间"; col5.Font = new Font("微软雅黑", 10.5f, FontStyle.Bold); col5.ForeColor = ColorTranslator.FromHtml("#333333"); col5.Location = new Point(540, 11); dataGridView1.Controls.Add(col5); col5.BringToFront(); Label col6 = new Label(); col6.Text = "采集原因"; col6.Font = new Font("微软雅黑", 10.5f, FontStyle.Bold); col6.ForeColor = ColorTranslator.FromHtml("#333333"); col6.Location = new Point(657, 11); dataGridView1.Controls.Add(col6); col6.BringToFront(); Label col7 = new Label(); col7.Text = "上传标识"; col7.Font = new Font("微软雅黑", 10.5f, FontStyle.Bold); col7.ForeColor = ColorTranslator.FromHtml("#333333"); col7.Location = new Point(751, 11); dataGridView1.Controls.Add(col7); col7.BringToFront(); totalCount = 0; currentPage = 1; pageCount = 0; limitCount = 10; LoadData(""); } private void CtrlCollectionFrom_Load(object sender, EventArgs e) { } private void LoadData(string searchStr) { DataTable table = irisCollViewService.GetColl(limitCount, currentPage, searchStr); totalCount = irisCollViewService.GetCollCount(searchStr); pageCount = totalCount / limitCount; int ys = totalCount % limitCount; if (ys != 0) pageCount++; setPageLabel(); dataGridView1.DataSource = table; initDataGridView(); //CheckBoxClass.dgv = dataGridView1; //CheckBoxClass.AddFullSelect(); //for (int index = 0; index < dataGridView1.Rows.Count; index++) //{ // DataGridViewCheckBoxCell cb = (DataGridViewCheckBoxCell)dataGridView1.Rows[index].Cells[0]; // if (dataGridView1.Rows[index].Cells[9].Value.ToString() == "已上传") // { // dataGridView1.EndEdit(); // cb.ReadOnly = true; // } //} } // 全选事件 private void ckBox_CheckedChanged(object sender, EventArgs e) { dataGridView1.EndEdit(); if (((CheckBox)sender).CheckState == CheckState.Checked) { for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { DataGridViewCheckBoxCell checkBox = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0]; checkBox.Value = true; } } else { for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { DataGridViewCheckBoxCell checkBox = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0]; checkBox.Value = false; } } } private void setPageLabel() { label3.Text = "共" + totalCount + "条,每页" + limitCount + "条,共" + pageCount + "页"; textBoxPage.Text = currentPage.ToString(); } private void initDataGridView() { dataGridView1.Columns[1].Visible = false; dataGridView1.Columns[2].Visible = false; dataGridView1.Columns[3].HeaderText = "人员姓名"; dataGridView1.Columns[4].HeaderText = "证件类型"; dataGridView1.Columns[5].HeaderText = "证件号码"; dataGridView1.Columns[6].HeaderText = "户籍地址"; dataGridView1.Columns[7].HeaderText = "采集时间"; dataGridView1.Columns[8].HeaderText = "采集原因"; dataGridView1.Columns[9].HeaderText = "是否上传"; dataGridView1.Columns[7].DefaultCellStyle.Format = "yyyy/MM/dd HH:mm:ss"; dataGridView1.Columns[0].Width = 40; dataGridView1.Columns[3].Width = 80; dataGridView1.Columns[4].Width = 90; dataGridView1.Columns[5].Width = 145; dataGridView1.Columns[6].Width = 180; dataGridView1.Columns[7].Width = 140; dataGridView1.Columns[8].Width = 120; dataGridView1.Columns[9].Width = 76; dataGridView1.Columns[3].ReadOnly = true; dataGridView1.Columns[4].ReadOnly = true; dataGridView1.Columns[5].ReadOnly = true; dataGridView1.Columns[6].ReadOnly = true; dataGridView1.Columns[7].ReadOnly = true; dataGridView1.Columns[8].ReadOnly = true; dataGridView1.Columns[9].ReadOnly = true; } /// <summary> /// 查询条件 /// </summary> /// <returns></returns> private string getSearchStr() { string upLoadCase = comboBoxUpLoad.Text; string cardNo = textBoxCardNo.Text; string searchStr = ""; if (cardNo != "") searchStr += " and ID_CARD_NO like '%" + textBoxCardNo.Text + "%'"; if (upLoadCase != "") { switch (upLoadCase) { case "未上传": searchStr += " and FLG_UPLOAD = 0"; break; case "已上传": searchStr += " and FLG_UPLOAD = 1"; break; case "上传失败": searchStr += " and FLG_UPLOAD = 2 or FLG_UPLOAD = 3"; break; default: break; } } return searchStr; } private void roundButtonSearch_Click(object sender, EventArgs e) { string searctStr = getSearchStr(); LoadData(searctStr); } private void roundButtonDelete_Click(object sender, EventArgs e) { int count = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) { DataGridViewRow row = dataGridView1.Rows[i]; Int64 personId = Convert.ToInt64(row.Cells["S_ID"].Value.ToString()); iUserIrisService.DeletePerson(personId); count++; } } if (count == 0) { MessageBox.Show("请至少选中一项","提示"); return; } else { if (MessageBox.Show("确认删除记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string searctStr = getSearchStr(); LoadData(searctStr); MessageBox.Show("采集记录删除成功","提示"); } } } /// <summary> /// 上传所选记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void roundButtonUpCheck_Click(object sender, EventArgs e) { try { List<RequestData> requestDatas = new List<RequestData>(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) { DataGridViewRow row = dataGridView1.Rows[i]; long ir_id = Convert.ToInt64(row.Cells["IR_ID"].Value.ToString()); RequestData requestData = data.dataConvert.ConvertTool.GetRequestDataBy(ir_id); requestDatas.Add(requestData); } } if (requestDatas.Count > 0) { if (MessageBox.Show("确认上传所选数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "requestData获取成功"); int code = dataSynchService.synchIrisCollData(requestDatas); if (code == 0) { string searctStr = getSearchStr(); LoadData(searctStr); MessageBox.Show("上传成功", "提示"); } else MessageBox.Show("上传失败", "提示"); } } else { MessageBox.Show("请至少选中一项", "提示"); return; } } catch (Exception ex) { MessageBox.Show("上传失败"); LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "上传选中数据失败:" + ex.Message); } } /// <summary> /// 上传所有记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void roundButtonUpAll_Click(object sender, EventArgs e) { try { if (MessageBox.Show("确认上传全部数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { List<RequestData> requestDatas = new List<RequestData>(); List<String> irIdList = new List<string>(); irIdList = irisCollViewService.GetIrIdList(); if (irIdList.Count == 0) { MessageBox.Show("没有未上传的数据", "提示"); } else { foreach (String irId in irIdList) { long ir_id = Convert.ToInt64(irId); RequestData requestData = data.dataConvert.ConvertTool.GetRequestDataBy(ir_id); requestDatas.Add(requestData); } LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "requestData获取成功"); int code = dataSynchService.synchIrisCollData(requestDatas); if (code == 0) { string searctStr = getSearchStr(); LoadData(searctStr); MessageBox.Show("上传成功", "提示"); } else MessageBox.Show("上传失败", "提示"); } } } catch(Exception ex) { MessageBox.Show("上传失败", "提示"); LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "全部上传失败:" + ex.Message); } } private void dataGridView1_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) return; DataGridViewRow row = dataGridView1.Rows[e.RowIndex]; try { Int64 s_id = Convert.ToInt64(row.Cells["S_ID"].Value.ToString()); Person person = new Person(); person.id = s_id; FormMain.person = new Person(); FormMain.irisDataColl = new IrisDataColl(); FormMain.irisData = new IrisData(); FormMain.personExt = new PersonExt(); iUserIrisService.GetDetail(s_id, ref FormMain.person, ref FormMain.personExt, ref FormMain.irisDataColl, ref FormMain.irisData); IInsertService insertService = new InsertImpl(); insertService.setToFirst(FormMain.formMain.panel_Insert); insertService.SetPanelControl(FormMain.formMain.panel_Insert, "detail"); FormMain.formMain.panel_Insert.BringToFront(); FormMain.formMain.panel4.Visible = false; FormMain.formMain.panel_steps.Visible = false; } catch (Exception ex) { MessageBox.Show("详情查看失败:" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void buttonNext_Click(object sender, EventArgs e) { if (currentPage < pageCount) { currentPage++; string searctStr = getSearchStr(); LoadData(searctStr); } } private void buttonPre_Click(object sender, EventArgs e) { if (currentPage > 1) { currentPage--; string searctStr = getSearchStr(); LoadData(searctStr); } } private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { dataGridView1.ClearSelection(); } private void comboBoxUpLoad_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxUpLoad.SelectedIndex > -1) txt_UpLoad.Text = comboBoxUpLoad.SelectedItem.ToString(); } private void btn_dropUpload_Click(object sender, EventArgs e) { comboBoxUpLoad.DroppedDown = true; } private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.RowIndex != -1) { DataGridViewCheckBoxCell cb = (DataGridViewCheckBoxCell)dataGridView1.Rows[e.RowIndex].Cells[0]; if (Convert.ToBoolean(cb.Value) == false) { ckBox.CheckState = CheckState.Unchecked; } } } private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (dataGridView1.IsCurrentCellDirty) { dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit); } } } }