using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WMS.Frm.Base; using WMS.Model.SystemManage; using WMS.Common; using WMS.Ctrl; using WMS.Model.Base; using DevExpress.XtraGrid.Columns; using DevExpress.XtraEditors.Repository; using WMS.Frm; using WMS.Business; using WMS.Business.Base; using WMS.Business.SystemManage; namespace WMS.FrmSystems { public partial class FrmTeam : FormBase { /// /// 班组MODEL /// TeamModel teamModel = new TeamModel(); /// /// 班组集合 /// List teamList = new List(); /// /// 班组人员Model /// TeamUserModel teamUserModel = new TeamUserModel(); /// /// 班组人员集合 /// List infoList = new List(); List tml = new List(); /// /// 业务类型 /// int workflag = 3;//0 增加 1 修改 2 删除 ; public FrmTeam() { InitializeComponent(); } private void FrmTeam_Load(object sender, EventArgs e) { BindTeam(); panelControl1.Visible = true; FrmSelectModle = new TeamModel(); BSTeamTab.DataSource = new TeamModel(); //this.txtTeamID.Enabled = false; //this.txtTeamName.Enabled = false; //this.txtPYName.Enabled = false; //this.DicMaster.Enabled = false; //this.DicTeam.Enabled = false; panelControl1.Enabled = false; bindlookupEdit(); if (teamList.Count > 0) { GVTeam_Click(null, null); } } /// /// 绑定下拉框 /// private void bindlookupEdit() { try { TLEP_DEP.Properties.DataSource = IBussFactory.Instance().getCompanytDataSet("", ""); TLEP_DEP.Properties.DisplayMember = "COM_NAME"; TLEP_DEP.Properties.ValueMember = "COM_ID"; } catch(Exception e) { SystemCommon.ShowInfoMessageBox("加载失败,请检查网络是否正常!"+e.Message); } } /// /// 绑定班组数据信息 /// private void BindTeam() { try { teamList = IBussFactory.Instance().GetList(new TeamModel()); GCTeam.DataSource = teamList; GVTeam.RefreshData(); } catch (Exception e) { SystemCommon.ShowErrorMessageBox(e.Message); } if (teamList.Count > 0) { BindTeamUser(teamList[0]); } else { infoList.Clear(); GCTeamUser.DataSource = infoList; GVTeamUser.RefreshData(); } } /// /// 绑定班组人员明细数据 /// /// private void BindTeamUser(TeamModel model) { try { infoList = IBussFactory.Instance().GetList(new TeamUserModel() { TEAM_ID = model.TEAM_ID }); GCTeamUser.DataSource = infoList; GVTeamUser.RefreshData(); } catch (Exception e) { SystemCommon.ShowInfoMessageBox("加载失败,请检查网络是否正常!" + e.Message); } } /// /// 通用查询 /// /// public override void LoadListData(DataTable table) { teamList = ConvertHelper.ConvertToList(table); GCTeam.DataSource = teamList; GVTeam.RefreshData(); if (teamList.Count > 0) { BindTeamUser(teamList[0]); } } #region 以下是继承的按钮事件 /// /// 新增按钮 /// public void Add() { frmButtonItem["Save"].Enabled = true; panelControl1.Visible = true; panelControl1.Enabled = true; workflag = 0; BSTeamTab.DataSource = new TeamModel(); txtTeamID.Select(); } /// /// 保存按钮 /// public void Save() { FrmOperator(workflag); panelControl1.Enabled = false; } /// /// 删除按钮 /// public void Del() { workflag = 2; if (SystemCommon.ShowMessageBoxResult("确定此班组及班组人员:" + GVTeam.GetFocusedRowCellValue("TEAM_ID").ToString()) == System.Windows.Forms.DialogResult.Yes) { Save(); } } /// /// 修改按钮 /// public void Edit() { if (string.IsNullOrEmpty(teamModel.TEAM_ID)) { return; } frmButtonItem["Save"].Enabled = true; workflag = 1; panelControl1.Visible = true; panelControl1.Enabled = true; BSTeamTab.DataSource = teamModel; DicMaster.TextBoxFlag = teamModel.TEAM_MASTER; DicMaster.TextBoxValue = teamModel.TEAM_MASTER_NAME; txtTeamID.Enabled = false; txtTeamName.Select(); } /// /// 刷新按钮 /// public void Refresh() { BindTeam(); panelControl1.Visible = true; } /// /// 确定按钮 /// public void ConfrimDataButton() { } /// /// 查询按钮 /// public void Search() { FrmSelect frm = new FrmSelect(this.FrmSelectModle); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.LoadListData(frm.SelectData); } } /// /// 导出按钮 /// public void ExportDataButton() { } /// /// 打印按钮 /// public void PrintDataButton() { } /// /// 备注 /// public void Remark() { //FrmSelectRemark frmSelectRemark = new FrmSelectRemark(); //frmSelectRemark.remarkType = "班组管理"; //frmSelectRemark.ShowDialog(); //if (frmSelectRemark.remarkType != "selected") { return; } //teamModel.REMARK = frmSelectRemark.baseRemarkDictionaryModel.CONTENT; //txtRemark.Text = frmSelectRemark.baseRemarkDictionaryModel.CONTENT; //txtRemark.ForeColor = System.Drawing.ColorTranslator.FromHtml(frmSelectRemark.baseRemarkDictionaryModel.COLOR_ID); } /// /// 审核 /// public void AuditDataButton() { } /// /// 反审核 /// public void ReturnAuditDataButton() { } #endregion #region 操作(增、改、删) /// /// 操作(增、改、删) /// /// 0 新增 1修改 2删除 3停用 4启用/param> private void FrmOperator(int flag) { BSTeamTab.EndEdit(); string errtxt = string.Empty; try { teamModel = BSTeamTab.DataSource as TeamModel; if (string.IsNullOrEmpty(teamModel.TEAM_ID)) { SystemCommon.ShowErrorMessageBox("请填写班组编号!"); return; } if (string.IsNullOrEmpty(teamModel.TEAM_NAME)) { SystemCommon.ShowErrorMessageBox("请填写班组名称!"); return; } teamModel.TEAM_MASTER = DicMaster.TextBoxFlag; infoList.Clear(); if (DicTeam.SelectTable.Rows.Count > 0) { foreach (DataRow row in DicTeam.SelectTable.Rows) { infoList.Add(new TeamUserModel() { TEAM_ID = teamModel.TEAM_ID, USER_ID = row["user_id"].ToString() }); } } if (flag == 0) { if (infoList.Count == 0) { if (SystemCommon.ShowMessageBoxResult("您还未给班组分配人员,是否继续?") == System.Windows.Forms.DialogResult.No) { return; } } errtxt = IBussFactory.Instance().AddAndList(teamModel, infoList); } else if (flag == 1) { if (infoList.Count == 0) { errtxt = IBussFactory.Instance().Update(teamModel); } else { errtxt = IBussFactory.Instance().UpdateAndList(teamModel, infoList); } } else if (flag == 2) { errtxt = IBussFactory.Instance().DeleteAndList(teamModel); } if (!string.IsNullOrEmpty(errtxt)) { SystemCommon.ShowErrorMessageBox(errtxt); } else { SystemCommon.ShowInfoMessageBox("操作成功!"); frmButtonItem["Save"].Enabled = false; Refresh(); GCTeam.Focus(); workflag = 3; txtTeamID.Enabled = true; GVTeam_Click(null, null); } } catch (Exception e) { SystemCommon.ShowInfoMessageBox("您的操作失败!" + Environment.NewLine + e.Message); } } #endregion private void GVTeam_Click(object sender, EventArgs e) { if (GVTeam.FocusedRowHandle > -1) { teamModel = GVTeam.GetFocusedRow() as TeamModel; BSTeamTab.DataSource = teamModel; DicMaster.TextBoxFlag = teamModel.TEAM_MASTER; DicMaster.TextBoxValue = teamModel.TEAM_MASTER_NAME; BindTeamUser(teamModel); } } private void txtTeamID_Leave(object sender, EventArgs e) { if (workflag == 0) { BSTeamTab.EndEdit(); teamModel = BSTeamTab.DataSource as TeamModel; if (!string.IsNullOrEmpty(teamModel.TEAM_ID)) { teamList = IBussFactory.Instance().GetList(teamModel); if (teamList.Count > 0) { SystemCommon.ShowErrorMessageBox("该班组编号已存在!"); teamModel.TEAM_ID = ""; BSTeamTab.ResetBindings(true); txtTeamID.Select(); } } } } private void DicTeam_Button_Click(object sender, EventArgs e) { if (this.DicTeam.SelectTable.Rows.Count > 0) { tml.Clear(); string errText = string.Empty; UserDataModel um = new UserDataModel(); List teamuserlis = ConvertHelper.ConvertToList(DicTeam.SelectTable); foreach (UserDataModel tm in teamuserlis) { teamUserModel = new TeamUserModel(); teamUserModel.USER_ID = tm.USER_ID; teamUserModel.USER_NAME = tm.NAME; teamUserModel.TEAM_ID = this.txtTeamID.Text; tml.Add(teamUserModel); } GCTeamUser.DataSource = tml; GVTeamUser.RefreshData(); infoList = tml; } } private void txtRemark_TextChanged(object sender, EventArgs e) { //if (this.GVTeam.FocusedRowHandle < 0) //{ // return; //} //else //{ // teamModel.REMARK = this.txtRemark.Text; //} } } }