Beispiel #1
0
        /// <summary>
        /// 获取考勤列表并保存到数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (m_gvTable.Rows.Count == 0)
            {
                XtraMessageBox.Show("提示", "先生成考勤日期", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (m_AttenTable == null)
            {
                m_AttenTable = new DataTable(Common.Column_AttendanceDate);
                DataColumn col = new DataColumn();
                col.ColumnName = Common.Column_AttendanceDate;
                col.DataType   = Type.GetType("System.DateTime");
                m_AttenTable.Columns.Add(col);
                col            = new DataColumn();
                col.ColumnName = Common.Column_AttenType;
                col.DataType   = Type.GetType("System.String");
                m_AttenTable.Columns.Add(col);
            }
            else
            {
                m_AttenTable.Rows.Clear();
            }
            int selectYear  = int.Parse(seYear.EditValue.ToString());
            int selectMonth = 0;

            foreach (int key in m_dicMothn.Keys)
            {
                if (m_dicMothn[key] == cbMonth.SelectedItem.ToString())
                {
                    selectMonth = key;
                    break;
                }
            }
            foreach (DataRow pRow in m_gvTable.Rows)
            {
                foreach (DataColumn col in m_gvTable.Columns)
                {
                    if (pRow[col] != DBNull.Value)
                    {
                        string[] rowValue = pRow[col].ToString().Split('-');
                        DataRow  pNewRow  = m_AttenTable.NewRow();
                        DateTime dt       = new DateTime(selectYear, selectMonth, int.Parse(rowValue[0]));
                        pNewRow[Common.Column_AttendanceDate] = dt;
                        pNewRow[Common.Column_AttenType]      = (int)m_dicAttenType[rowValue[1]];
                        m_AttenTable.Rows.Add(pNewRow);
                    }
                }
            }
            //先删后加
            DateTime minDt = new DateTime(selectYear, selectMonth, 1);
            DateTime maxDt = minDt.AddMonths(1);

            maxDt = maxDt.AddDays(0 - maxDt.Day);

            if (!m_dbOperator.DelData(Common.Table_AttenDate,
                                      string.Format("{0} between #{1}# and #{2}#",
                                                    Common.Column_AttendanceDate, minDt.ToString("yyyy-MM-dd"), maxDt.ToString("yyyy-MM-dd"))))
            {
                XtraMessageBox.Show("删除数据出错", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (m_dbOperator.ImportDataTable(m_AttenTable))
            {
                XtraMessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                XtraMessageBox.Show("保存失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }