using DevExpress.XtraEditors; using System; using System.Web.UI.WebControls; using System.Windows.Forms; using ZJ_BYD.Common; using ZJ_BYD.DB; using ZJ_BYD.Model; namespace ZJ_BYD.UserControls.MachineTypeStation { public partial class EditMachineTypeStation : Form { public EditMachineTypeStation(int id = 0) { InitializeComponent(); BindCombox.BindMachineType(cmbMachineType); BindCombox.BindStation(cmbStation); if (id > 0) { GetMachineTypeStationById(id); } else { lblIsUsed.Text = "否"; } } private void GetMachineTypeStationById(int id) { var model = MachineTypeStationRelationHelper.QueryMaChineTypeStationVM().First(a => a.Id == id); if (model != null) { lblId.Text = model.Id.ToString(); lblIsUsed.Text = model.StrIsUsed; cmbStation.SelectedItem = new ListItem { Text=model.StationName,Value=model.StationCode}; cmbMachineType.SelectedItem = new ListItem { Text = model.MachineTypeCode, Value = model.MachineTypeCode }; } } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void btnSave_Click(object sender, EventArgs e) { int row; var selectedStation = this.cmbStation.SelectedItem as ListItem; var selectedMachineType = this.cmbMachineType.SelectedItem as ListItem; if (string.IsNullOrWhiteSpace(lblId.Text)) { var t_MachineTypeStationRelation = new T_MachineTypeStationRelation { IpcId = Program.CurrentIpcId, LineCode = Program.CurrentLineCode, StationCode = selectedStation.Value, MachineTypeCode = selectedMachineType.Value, IsUsed = !string.IsNullOrWhiteSpace(lblIsUsed.Text) && (lblIsUsed.Text == "是" ? true : false), CreatedTime = DateTime.Now, CreatedBy = CurrentUser.UserName }; row = MachineTypeStationRelationHelper.AddMachineTypeStationRelation(t_MachineTypeStationRelation); } else { var t_MachineTypeStationRelation = new T_MachineTypeStationRelation { Id = int.Parse(this.lblId.Text), IpcId = Program.CurrentIpcId, LineCode = Program.CurrentLineCode, StationCode = selectedStation.Value, MachineTypeCode = selectedMachineType.Value, IsUsed = !string.IsNullOrWhiteSpace(lblIsUsed.Text) && (lblIsUsed.Text == "是" ? true : false), UpdatedBy = CurrentUser.UserName, UpdatedTime = DateTime.Now }; row = MachineTypeStationRelationHelper.UpdateMachineTypeStationRelation(t_MachineTypeStationRelation); } if (row <= 0) { XtraMessageBox.Show("操作失败!"); return; } XtraMessageBox.Show("操作成功!"); this.DialogResult = DialogResult.OK; this.Close(); } } }