private void barButtonItem查询_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
barStaticItem3.Caption = "正在执行:查询";
DataSet ds = new DataSet();
string strwhere = " where 1=1";
if (barCheckItem1.Checked)
{
strwhere += " and 变更日期 <'" + ((DateTime)barEditItem2.EditValue).Date.AddDays(1) + "' and 截止日期> '" + ((DateTime)barEditItem1.EditValue).Date + "' ";
}
else
{
strwhere += " and 变更日期 <'" + ((DateTime)barEditItem2.EditValue).Date.AddDays(1) + "' and 截止日期> '" + ((DateTime)barEditItem2.EditValue).Date + "' ";
}
if (DbHelperSQL2.Authorized("部门用户"))
{
strwhere += " and 部门编号='" + MainForm.UserDepartmentid + "' ";
}
//ds = DbHelperSQL2.Query("select * from employeeR " + strwhere);// where 收入日期<= Convert(nvarchar(7),'" + ((DateTime)barEditItem2.EditValue).ToString("yyyy-MM") + "',120) and 日期>= Convert(nvarchar(7),'" + ((DateTime)barEditItem1.EditValue).ToString("yyyy-MM") + "',120)");
bandedGridView1.Columns.Clear();
//gridControl1.DataSource = null;
//gridControl1.DataSource = ds.Tables[0];
string SQLString = "select * from employeeR " + strwhere;
using (SqlConnection connection = new SqlConnection(Conn.sqlstr))
{
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
}
gridControl1.DataSource = ds.Tables[0];
gridfile = System.Windows.Forms.Application.StartupPath + "//" + MainForm.UserName + "//" + this.Name + "grid.xml";
if (comboBoxEdit1.EditValue != null)
{
gridControl1.LookAndFeel.SkinName = comboBoxEdit1.EditValue.ToString();
}
if (cbeStyles.EditValue != null)
{
xapp.LoadScheme(cbeStyles.EditValue.ToString(), gridControl1.DefaultView); //gridControl1.MainView;
}
if (System.IO.File.Exists(Appearancefile))
{
bandedGridView1.Appearance.RestoreLayoutFromXml(Appearancefile);
}
if (System.IO.File.Exists(gridfile))
{
bandedGridView1.RestoreLayoutFromXml(gridfile);
}
string[] strs ={ "变更日期", "截止日期", "录入时间" };
foreach (string var in strs)
{
if (bandedGridView1.Columns[var].Visible)
{
bandedGridView1.Columns[var].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
bandedGridView1.Columns[var].DisplayFormat.FormatString = "G";
}
}
bandedGridView1.Columns["ID"].OptionsColumn.ReadOnly = true;
bandedGridView1.Columns["ID"].OptionsColumn.AllowEdit = false;
bandedGridView1.Columns["录入时间"].OptionsColumn.ReadOnly = true;//只读,不可选择,不可修改
bandedGridView1.Columns["录入时间"].OptionsColumn.AllowEdit = false;//可选择,不可修改
bandedGridView1.Columns["录入人员"].OptionsColumn.ReadOnly = true;
bandedGridView1.Columns["录入人员"].OptionsColumn.AllowEdit = false;
bandedGridView1.Columns["录入部门"].OptionsColumn.ReadOnly = true;
bandedGridView1.Columns["录入部门"].OptionsColumn.AllowEdit = false;
barStaticItem2.Caption = "共计:" + bandedGridView1.RowCount + " 条记录";
barStaticItem1.Caption = "没有选中任何记录";
barStaticItem3.Caption = "查询完毕";
}