private void tsbSave_Click(object sender, EventArgs e) { if (MessageService.AskQuestion("你确定要保存当前界面的数据吗?", "保存")) { MapControlsToSupplier(); bool IsTrue = false; if (_supplierEntity.SupplierCode == string.Empty) { MessageService.ShowMessage("供应商代码不为空", "保存"); //名称不能为空! return; } if (_supplierEntity.SupplierName == string.Empty) { MessageService.ShowMessage("供应商名称不为空", "保存"); //名称不能为空! return; } if (_supplierEntity.SupplierNickName == string.Empty) { MessageService.ShowMessage("简称不为空", "保存"); //名称不能为空! return; } if (CtrlState == ControlState.New && _supplierEntity.GetSupplierCode(_supplierEntity.SupplierName, "").Tables[0].Rows.Count > 0) { MessageService.ShowMessage("当前供应商代码已经存在,请重新设置", "保存"); //当前名称已存在! return; } if (CtrlState == ControlState.New) { //状态为new if (_supplierEntity.Insert()) { //新增成功 IsTrue = true; } } else {//状态不为new if (lblCode.Text.ToString() != "") { if (_supplierEntity.Update(lblCode.Text.ToString())) {//修改成功 IsTrue = true; } } else { MessageService.ShowMessage("请选择要修改的供应商信息", "保存"); //当前名称已存在! } } if (IsTrue) { //值为true BindSupplierCode(); //数据表数据重新绑定 CtrlState = ControlState.ReadOnly; //状态为readonly } } }
/// <summary> /// 查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnQuery_Click(object sender, EventArgs e) { DataSet dataSet = new DataSet(); SupplierEntity supplierEntity = new SupplierEntity(); dataSet = supplierEntity.GetSupplierCode(txtName.Text.ToString().Trim(), lueCode.EditValue.ToString()); if (dataSet != null) { grdCrtlCode.MainView = gridViewCode; grdCrtlCode.DataSource = dataSet.Tables[0]; gridViewCode.BestFitColumns(); } }
/// <summary> /// 绑定供应商代码 /// </summary> public void BindSupplierCode() { DataSet dataSet = new DataSet(); SupplierEntity supplierEntity = new SupplierEntity(); dataSet = supplierEntity.GetSupplierCode(); if (dataSet != null) { DataTable dt = dataSet.Tables[0].Copy(); dt.Rows.InsertAt(dt.NewRow(), 0); this.lueCode.Properties.DataSource = dt; this.lueCode.Properties.DisplayMember = "CODE"; this.lueCode.Properties.ValueMember = "CODE"; lueCode.ItemIndex = 0; grdCrtlCode.MainView = gridViewCode; grdCrtlCode.DataSource = dataSet.Tables[0]; gridViewCode.BestFitColumns(); } }