/// <summary> /// 数据保存 /// </summary> /// <param name="p">药理分类对象</param> /// <returns>返回结果</returns> public bool SavePharmacy(DG_Pharmacology p) { List <Tuple <string, string, SqlOperator> > lst = new List <Tuple <string, string, SqlOperator> >(); lst.Add(Tuple.Create("PharmName", p.PharmName, SqlOperator.Equal)); lst.Add(Tuple.Create("delflag", "0", SqlOperator.Equal)); lst.Add(Tuple.Create("parentid", p.ParentID.ToString(), SqlOperator.Equal)); IEnumerable <DG_Pharmacology> objs = NewObject <IDGDao>().GetEntityType <DG_Pharmacology>(lst, null); var vp = objs.FirstOrDefault(i => i.PharmID == p.PharmID); if (vp != null) { p.save(); return(true); } if (objs != null && objs.Any()) { //同名记录存在 return(false); } p.save(); return(true); }
/// <summary> /// 改变选中行事件 /// </summary> /// <param name="sender">对象</param> /// <param name="e">参数</param> private void dgFharm_CurrentCellChanged(object sender, EventArgs e) { if (dgFharm.CurrentCell == null) { return; } int rowindex = dgFharm.CurrentCell.RowIndex; DataTable dt = (DataTable)dgFharm.DataSource; DG_Pharmacology pruDic = EFWCoreLib.CoreFrame.Common.ConvertExtend.ToObject <DG_Pharmacology>(dt, rowindex); CurrentData = pruDic; this.txtName.Text = pruDic.PharmName; }
/// <summary> /// 点击操作 /// </summary> /// <param name="sender">对象</param> /// <param name="e">参数</param> private void dgFharm_Click(object sender, EventArgs e) { if (dgFharm.CurrentCell == null) { return; } int rowindex = dgFharm.CurrentCell.RowIndex; DataTable dt = (DataTable)dgFharm.DataSource; DG_Pharmacology pruDic = new DG_Pharmacology(); pruDic.PharmID = Convert.ToInt32(dt.Rows[rowindex]["PharmID"]); pruDic.PharmName = dt.Rows[rowindex]["PharmName"].ToString(); pruDic.ParentID = Convert.ToInt32(nodeTag); CurrentData = pruDic; this.txtName.Text = pruDic.PharmName; }
/// <summary> /// 保存操作 /// </summary> /// <param name="sender">对象</param> /// <param name="e">参数</param> private void btnSave_Click(object sender, System.EventArgs e) { bool flag = false;//标识状态 true:修改 false:新增 this.txtName.Focus(); DG_Pharmacology productDic = null; if (string.IsNullOrEmpty(this.txtName.Text.Trim())) { MessageBoxEx.Show("请输入类型名称"); return; } if (string.IsNullOrEmpty(nodeTag)) { MessageBoxEx.Show("请选择上级列数据"); return; } if (CurrentData != null) { if (MessageBox.Show("确定更改记录?", string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } productDic = CurrentData; flag = true; } else { productDic = new DG_Pharmacology(); } productDic.ParentID = Convert.ToInt32(nodeTag); productDic.PharmName = this.txtName.Text.Trim(); productDic.PYCode = EFWCoreLib.CoreFrame.Common.SpellAndWbCode.GetSpellCode(productDic.PharmName); productDic.WBCode = EFWCoreLib.CoreFrame.Common.SpellAndWbCode.GetWBCode(productDic.PharmName); CurrentData = productDic; bool isSave = (bool)InvokeController("SavePharmacy"); DataTable dt = dgFharm.DataSource as DataTable; if (isSave) { if (flag) { dt.Rows[rowIndex]["PharmName"] = productDic.PharmName; dt.Rows[rowIndex]["PYCode"] = productDic.PYCode; } else { DataRow dr = dt.NewRow(); dr["PharmName"] = productDic.PharmName; dr["PYCode"] = productDic.PYCode; dr["PharmID"] = key; dr["PNAME"] = nodeText; dt.Rows.Add(dr); } SetGridSelectIndex(dgFharm); } }
/// <summary> /// 更新为删除状态 /// </summary> /// <param name="p">药理分类对象</param> public void UpdatePharmacy(DG_Pharmacology p) { p.Delflag = 1; p.save(); }