|
|
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using ICSSoft.Frame.WorkPoint.Entity; using ICSSoft.Frame.WorkPoint.BLL; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.Config.DBHelper; using System.Text.RegularExpressions; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; using ICSSoft.Frame.Helper; using ICSSoft.Base.ReferForm.AppReferForm;
namespace ICSSoft.Frame.APP { public partial class FormICSTPAdd : DevExpress.XtraEditors.XtraForm { ICSTP personInfo; int flag;
public FormICSTPAdd() { InitializeComponent(); flag = 0;
txtTPCode.ReadOnly = false; comTPType.Items.Clear(); comIsOverDate.Items.Clear();
comTPType.Items.Add("正常班"); comTPType.Items.Add("加班");
comIsOverDate.Items.Add("是"); comIsOverDate.Items.Add("否"); DataTable dv = ICSTPBLL.SelectTPCode(); txtID.Text = AppConfig.GetGuid(); txtUser.Text = AppConfig.UserCode; txtUseTime.Text = DateTime.Now.ToShortDateString(); }
public FormICSTPAdd(string id,string shifttypecode,string shiftcode) { InitializeComponent(); txtSHIFTTYPEID.Text = shifttypecode; txtSHIFTID.Text = shiftcode; flag = 1; labTop.Text = "修改时段信息"; comTPType.Items.Clear(); comIsOverDate.Items.Clear(); comTPType.Items.Add("加班"); comTPType.Items.Add("不加班");
comIsOverDate.Items.Add("是"); comIsOverDate.Items.Add("否"); comTPType.DropDownStyle = ComboBoxStyle.DropDown; comIsOverDate.DropDownStyle = ComboBoxStyle.DropDown; SearchMandayInfo(id); } private void SearchMandayInfo(string Id) { personInfo = ICSTPBLL.SearchPersonInfoByCode(Id, AppConfig.AppConnectString); txtID.Text = personInfo.ID; txtTPCode.Text= personInfo.TPCODE; txtItemCode.Text = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTTPID(personInfo.SHIFTTYPEID).Rows[0][0].ToString(); btnShift.Text = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTPID(personInfo.SHIFTID).Rows[0][0].ToString(); rTPDesc.Text=personInfo.TPDESC; txtTPSeq.Text=personInfo.TPSEQ.ToString() ; comTPType.Text=personInfo.TPTYPE; dBegTime.EditValue = FormatHelper.ToTimeString(personInfo.TPBTIME); dEndTime.EditValue = FormatHelper.ToTimeString(personInfo.TPETIME); // dBegTime.Text = FormatHelper.ToTimeString(personInfo.TPBTIME);
// dEndTime.Text = FormatHelper.ToTimeString(personInfo.TPETIME);
comIsOverDate.Text=personInfo.ISOVERDATE ; txtUser.Text=personInfo.MUSER ; txtUseTime.Text=personInfo.MTIME.ToString(); }
#region 移动窗体
private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
//系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
//假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
//同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
//重写窗体,使窗体可以不通过自带标题栏实现移动
protected override void WndProc(ref Message m) {
//当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
//当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
//这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
//注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息
if (m.Msg != 0xA3) { base.WndProc(ref m); }
} #endregion
private void btnClose_Click(object sender, EventArgs e) { this.Close(); }
private void btnCancle_Click(object sender, EventArgs e) { this.Close(); this.DialogResult = DialogResult.Cancel; }
private void btnOK_Click(object sender, EventArgs e) { //1、开始时间不能早于结束时间 2、时间在班次时间之内 3、时间段不能重叠
Regex rex = new Regex(@"^\d+$"); int i = 0; int j = 0; //时段代码
DataTable dy=ICSTPBLL.SelectTPCode(); if (flag == 0) { foreach (DataRow dr in dy.Rows) { if (txtTPCode.Text == dr[0].ToString()) { i++; } } } //判断为空
if (rTPDesc.Text == "" || txtTPSeq.Text == "" || dBegTime.Text == "" || dEndTime.Text == "" || dBegTime.Text == "" || dEndTime.Text == "") { ICSBaseSimpleCode.AppshowMessageBox("不可为空!"); return; } //获取输入值 开始时间、结束时间、是否跨天
int begtime; int endtime; if (dBegTime.Text.Length == 8) { begtime = int.Parse(dBegTime.Text.Substring(0, 2) + dBegTime.Text.Substring(3, 2) + dBegTime.Text.Substring(6, 2)); } else { begtime = int.Parse(dBegTime.Text.Substring(0, 1) + dBegTime.Text.Substring(2, 2) + dBegTime.Text.Substring(5, 2)); } if (dEndTime.Text.Length == 8) { endtime = int.Parse(dEndTime.Text.Substring(0, 2) + dEndTime.Text.Substring(3, 2) + dEndTime.Text.Substring(6, 2)); }
else { endtime = int.Parse(dEndTime.Text.Substring(0, 1) + dEndTime.Text.Substring(2, 2) + dEndTime.Text.Substring(5, 2)); } // int begtime = int.Parse((dBegTime.Text.Substring(0,2)+dBegTime.Text.Substring(3,2)+dBegTime.Text.Substring(6,2)).ToString());
// int endtime = int.Parse((dEndTime.Text.Substring(0, 2) + dEndTime.Text.Substring(3, 2) + dEndTime.Text.Substring(6, 2)).ToString());
string isoverday=comIsOverDate.Text; if (isoverday == "是") { isoverday += 120000; }
//获取表中存在的开始结束时间、是否跨天信息
DataTable bt = ICSTPBLL.SelectTPTime(txtSHIFTTYPEID.Text,txtSHIFTID.Text); //判断时间段是否重叠
foreach (DataRow dd in bt.Rows) { if (dd["ID"].ToString() != txtID.Text) { int tpbtime = int.Parse(dd[0].ToString());//开始时间
int tpetime = int.Parse(dd[1].ToString());//结束时间
string over = dd[3].ToString(); if (over == "是") { tpetime += 120000; } if (begtime > tpbtime && begtime < tpetime) { j++; } else if (endtime > tpbtime && endtime < tpetime) { j++; } else if (begtime > tpbtime && endtime < tpetime) { j++; } else if (begtime < tpbtime && endtime > tpetime) { j++; } else if (isoverday == "是" && over == "是") { j++; } } } //获取班次的开始结束时间、是否跨天
string sbt = ICSTPBLL.SelectBegTime(btnShift.Text).Rows[0][0].ToString(); string set = ICSTPBLL.SelectEndTime(btnShift.Text).Rows[0][0].ToString(); int sbegtime = int.Parse(sbt); int sendtime = int.Parse(set); string sisoverday =ICSTPBLL.SelectIsOverDay(btnShift.Text).Rows[0][0].ToString(); if (sisoverday == "是") { sendtime += 120000; }
if (!rex.Match(txtTPSeq.Text).Success) { ICSBaseSimpleCode.AppshowMessageBox("时段次序只可填入正整数!"); return; } else if (i != 0 && flag == 0)//判断 新增 时[时段代码]是否唯一
{ ICSBaseSimpleCode.AppshowMessageBox("时段代码已存在!"); return; } else if (endtime <= begtime ) { ICSBaseSimpleCode.AppshowMessageBox("开始时间不能等于或早于结束时间!"); return; } else if(j!=0) { ICSBaseSimpleCode.AppshowMessageBox("同一班制的时段时间不能重叠!"); return; } else if(isoverday=="是" && sisoverday == "否") { ICSBaseSimpleCode.AppshowMessageBox("所属的[班次]没有跨天!"); return; } else if(begtime<sbegtime||endtime>sendtime) { ICSBaseSimpleCode.AppshowMessageBox("时间超出[班次]时间范围!"); return; } else if (comTPType.Text != "正常班" && comTPType.Text != "加班") { ICSBaseSimpleCode.AppshowMessageBox("[时段类型]错误!"); return; } else if (comIsOverDate.Text != "是" && comIsOverDate.Text != "否") { ICSBaseSimpleCode.AppshowMessageBox("[是否跨天]错误!"); return; } else { try { ICSTP personInfo = new ICSTP(); personInfo.ID = txtID.Text; personInfo.TPCODE = txtTPCode.Text; personInfo.SHIFTTYPEID = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTTPID1(txtItemCode.Text).Rows[0][0].ToString(); personInfo.SHIFTID = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTPID1(btnShift.Text).Rows[0][0].ToString(); personInfo.TPDESC = rTPDesc.Text; personInfo.TPSEQ = int.Parse(txtTPSeq.Text); personInfo.TPTYPE = comTPType.Text; personInfo.TPBTIME = begtime; personInfo.TPETIME = endtime; // personInfo.TPBTIME = int.Parse(dBegTime.Text.Substring(0, 2) + dBegTime.Text.Substring(3, 2) + dBegTime.Text.Substring(6, 2));
// personInfo.TPETIME = int.Parse(dEndTime.Text.Substring(0, 2) + dEndTime.Text.Substring(3, 2) + dEndTime.Text.Substring(6, 2));
personInfo.ISOVERDATE = comIsOverDate.Text; personInfo.MUSER = txtUser.Text; personInfo.MUSERName = AppConfig.UserName; personInfo.MTIME = System.DateTime.Parse(txtUseTime.Text); personInfo.WorkPoint = AppConfig.WorkPointCode; ICSTPBLL.Add(personInfo, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("操作成功!"); this.Close(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } }
private void txtItemCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (btnShift.Text != "") { btnShift.Text = ""; } txtItemCode.Text = ""; ButtonEdit btn = (ButtonEdit)sender; string sql = @"select SHIFTTYPECODE as [班制代码],SHIFTTYPEDESC as [描述],EFFDATE as [开始时间],IVLDATE as [结束时间],ID
from dbo.ICSSHIFTTYPE where WorkPoint='"+AppConfig.WorkPointCode+"'";
sql = string.Format(sql); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; FormDataRefer reForm = new FormDataRefer(); reForm.FormTitle = "班制信息"; DataTable menuData = data; reForm.DataSource = menuData; reForm.MSelectFlag = false; reForm.RowIndexWidth = 35; reForm.HideCols.Add("ID"); reForm.FormWidth = 800; reForm.FormHeight = 600; reForm.FilterKey = btn.Text; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
if (reForm.ShowDialog() == DialogResult.OK) { DataTable retData = reForm.ReturnData; foreach (DataRow dr in retData.Rows) { txtItemCode.Text = dr["班制代码"].ToString();
} } }
private void btnShift_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if(txtItemCode.Text=="") { ICSBaseSimpleCode.AppshowMessageBox("请先选择[班制代码]!"); return; } btnShift.Text = ""; ButtonEdit btn = (ButtonEdit)sender; string str = ICSTPBLL.SelectSTTPID1(txtItemCode.Text).Rows[0][0].ToString(); string sql = @"select SHIFTCODE as [班次编码],SHIFTDESC as [描述],ISOVERDAY as [是否跨天],SHIFTBTIME as [开始时间],SHIFTETIME as [结束时间],ID
from dbo.ICSSHIFT where SHIFTTYPEID='" + str + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
sql = string.Format(sql); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; DataTable dt = new DataTable(); dt.Columns.Add("SHIFTCODE", typeof(string)); dt.Columns["SHIFTCODE"].ColumnName = "班次编码"; dt.Columns.Add("SHIFTDESC", typeof(string)); dt.Columns["SHIFTDESC"].ColumnName = "描述"; dt.Columns.Add("ISOVERDAY", typeof(string)); dt.Columns["ISOVERDAY"].ColumnName = "是否跨天"; dt.Columns.Add("SHIFTBTIME", typeof(string)); dt.Columns["SHIFTBTIME"].ColumnName = "开始时间"; dt.Columns.Add("SHIFTETIME", typeof(string)); dt.Columns["SHIFTETIME"].ColumnName = "结束时间"; if (data != null && data.Rows.Count > 0) { for (int i = 0; i < data.Rows.Count;i++ ) { DataRow dr = dt.NewRow(); dr["班次编码"] = data.Rows[i]["班次编码"].ToString(); dr["描述"] = data.Rows[i]["描述"].ToString(); dr["是否跨天"] = data.Rows[i]["是否跨天"].ToString(); dr["开始时间"] = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(data.Rows[i]["开始时间"].ToString())); dr["结束时间"] = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(data.Rows[i]["结束时间"].ToString())); dt.Rows.Add(dr); }
} FormDataRefer reForm = new FormDataRefer(); reForm.FormTitle = "班次信息"; DataTable menuData = dt; reForm.DataSource = menuData; reForm.MSelectFlag = false; reForm.RowIndexWidth = 35; reForm.HideCols.Add("ID"); reForm.FormWidth = 800; reForm.FormHeight = 600; reForm.FilterKey = btn.Text; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
if (reForm.ShowDialog() == DialogResult.OK) { DataTable retData = reForm.ReturnData; foreach (DataRow dr in retData.Rows) { btnShift.Text = dr["班次编码"].ToString(); } } }
private void txtTPCode_TextChanged(object sender, EventArgs e) {
}
} }
|