//提取申请时拆分申请药品 public static DataTable YF_RKSQ_CK(Guid djid, long deptid, long deptid_sq, RelationalDatabase _DataBase) { try { ParameterEx[] parameters = new ParameterEx[3]; parameters[0].Text = "@djid"; parameters[0].Value = djid; parameters[1].Text = "@deptid"; parameters[1].Value = deptid; parameters[2].Text = "@deptid_sq"; parameters[2].Value = deptid_sq; DataTable tb; if (YpConfig.是否药库(deptid, _DataBase) == true) { tb = _DataBase.GetDataTable("SP_YK_RKSQ_CK", parameters, 30); } else { tb = _DataBase.GetDataTable("SP_YF_RKSQ_CK", parameters, 30); } return(tb); } catch (System.Exception err) { throw new System.Exception(err.ToString()); } }
/// <summary> /// 出库单转换为目的科室的入库待审核单据 /// </summary> /// <param name="ywlx">业务类型</param> /// <param name="sqks">目的科室</param> /// <param name="deptid">当前科室</param> /// <param name="ckdh">出库单号</param> /// <param name="sqdh">申请单据号</param> /// <param name="djid">产生的yk_dj的ID</param> /// <param name="err_code">错误号</param> /// <param name="err_text">错误文本</param> public static void Add_Ck_RkDjmx(Guid Ydjid, string ywlx, long sqks, long deptid, long ckdh, long sqdh, out Guid djid, out int err_code, out string err_text, long toJgbm, RelationalDatabase _DataBase) { ParameterEx[] parameters = new ParameterEx[10]; parameters[0].Text = "@djh"; parameters[0].Value = ckdh; parameters[1].Text = "@deptid"; parameters[1].Value = deptid; parameters[2].Text = "@sqdh"; parameters[2].Value = sqdh; parameters[3].Text = "@sqks"; parameters[3].Value = sqks; parameters[4].Text = "@ywlx"; parameters[4].Value = ywlx; parameters[5].Text = "@djid"; parameters[5].ParaDirection = ParameterDirection.Output; parameters[5].DataType = System.Data.DbType.Guid; parameters[5].ParaSize = 100; parameters[6].Text = "@err_code"; parameters[6].ParaDirection = ParameterDirection.Output; parameters[6].DataType = System.Data.DbType.Int32; parameters[6].ParaSize = 100; parameters[7].Text = "@err_text"; parameters[7].ParaDirection = ParameterDirection.Output; parameters[7].ParaSize = 100; parameters[8].Text = "@tojgbm"; parameters[8].Value = toJgbm; parameters[9].Text = "@ydjid"; parameters[9].Value = Ydjid; DataTable tb; if (YpConfig.是否药库(deptid, _DataBase) == true) { tb = _DataBase.GetDataTable("sp_Yk_Rksq_Insert_Djmx", parameters, 30); } else { tb = _DataBase.GetDataTable("sp_Yf_Rksq_Insert_Djmx", parameters, 30); } djid = new Guid(Convertor.IsNull(parameters[5].Value.ToString(), Guid.Empty.ToString())); err_code = Convert.ToInt32(parameters[6].Value); err_text = Convert.ToString(parameters[7].Value); }
/// <summary> /// FrmShowCard查询窗口 /// </summary> /// <param name="sender">引发的控件</param> /// <param name="_ShowCardType">查询类型权举</param> /// <param name="Fid">其它条件ID</param> /// <param name="point">位置 </param> public static void frmShowCard(object sender, ShowCardType _ShowCardType, string functionName, long Fid, Point point, int deptid, RelationalDatabase _DataBase) { //SystemCfg sc = new SystemCfg(8201); //if (sc.Config == "0") //{ // frmShowCard(sender, _ShowCardType, Fid, point, deptid, _DataBase); // return; //} Control control = (Control)sender; if (control.Text.Trim() == "") { control.Text = ""; control.Tag = "0"; } string[] GrdMappingName; int[] GrdWidth; string[] sfield; string ssql = ""; Fshowcard f; if (_ShowCardType == ShowCardType.库存药品) { GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "库存", "单位", "DWBL", "批发价", "零售价", "货号" }; GrdWidth = new int[] { 0, 0, 30, 140, 90, 90, 60, 30, 0, 60, 60, 100 }; sfield = new string[] { "wbm", "pym", "szm", "ywm", "ypbm" }; /* * update code by pengy 7-2 10:17 * 按系统参数设置获取库存是否大于等于0的数据 */ ssql = "select config from jc_config where id = '8200'"; DataTable paramTable = _DataBase.GetDataTable(ssql); bool ypkc = paramTable != null && paramTable.Rows.Count > 0 && paramTable.Rows[0][0].ToString().Trim() == "1" ? true : false; if (YpConfig.是否药库(deptid, _DataBase) == true) { if (ypkc) { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL >= 0 and deptid={0} and bdelete_kc=0 and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0}) and cjid in (select cjid from YP_YPCJD where iswbyp =1)", deptid); } else { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid={0} and bdelete_kc=0 and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0}) and cjid in (select cjid from YP_YPCJD where iswbyp =1)", deptid); } } else { if (ypkc) { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl/dwbl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL >= 0 and deptid={0} and bdelete_kc=0 and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0}) and cjid in (select cjid from YP_YPCJD where iswbyp =1)", deptid); } else { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl/dwbl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid={0} and bdelete_kc=0 and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0}) and cjid in (select cjid from YP_YPCJD where iswbyp =1)", deptid); } } f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql, _DataBase); f.Location = point; f.Text = "库存药品"; f.Width = 700; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } else if (_ShowCardType == ShowCardType.库存药品_不区分禁用) { GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "库存", "单位", "DWBL", "批发价", "零售价", "货号" }; GrdWidth = new int[] { 0, 0, 30, 140, 90, 90, 60, 30, 0, 60, 60, 100 }; sfield = new string[] { "wbm", "pym", "szm", "ywm", "ypbm" }; if (YpConfig.是否药库(deptid, _DataBase) == true) { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid={0} and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0})", deptid); } else { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl/dwbl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid={0} and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0})", deptid); } f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql, _DataBase); f.Location = point; f.Text = "库存药品"; f.Width = 700; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } else if (_ShowCardType == ShowCardType.库存药品_外用药品) { GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "单位", "DWBL", "批发价", "零售价", "货号" }; GrdWidth = new int[] { 0, 0, 30, 140, 90, 90, 30, 0, 60, 60, 100 }; sfield = new string[] { "wbm", "pym", "szm", "ywm", "ypbm" }; if (YpConfig.是否药库(deptid, _DataBase) == true) { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and wyyp=1 and deptid={0} and bdelete_kc=0 and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0}) ", deptid); } else { ssql = string.Format(@"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and wyyp=1 and deptid={0} and bdelete_kc=0 and YPLX in (select distinct YPLX from YP_GLLX a left join YP_YPLX b on a.YPLX = b.ID where DEPTID = {0})", deptid); } f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql, _DataBase); f.Location = point; f.Text = "外用药品"; f.Width = 700; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } }
/// <summary> /// FrmShowCard查询窗口 /// </summary> /// <param name="sender">引发的控件</param> /// <param name="_ShowCardType">查询类型权举</param> /// <param name="Fid">其它条件ID</param> /// <param name="point">位置 </param> public static void frmShowCard_wbks(object sender, ShowCardType _ShowCardType, long Fid, Point point, int deptid, RelationalDatabase _DataBase) { Control control = (Control)sender; if (control.Text.Trim() == "") { control.Text = ""; control.Tag = "0"; } string[] GrdMappingName; int[] GrdWidth; string[] sfield; string ssql = ""; Fshowcard f; if (_ShowCardType == ShowCardType.剂型) { GrdMappingName = new string[] { "id", "药品剂型", "拼音码", "五笔码" }; GrdWidth = new int[] { 0, 150, 100, 100 }; //if (Convertor.IsNull(control.Tag.ToString(),"0")!="0") sfield = new string[] { "wbm", "pym", "", "", "" }; //else // sfield=new string[] {"","","","",""}; ssql = "select id,mc,pym,wbm from yp_ypjx where id<>0 ";//yplx="+Convert.ToInt32(Convertor.IsNull(Fid,"0"))+" "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "药品剂型"; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Text = row["mc"].ToString(); control.Tag = row["id"].ToString(); } } if (_ShowCardType == ShowCardType.单位) { GrdMappingName = new string[] { "标识", "名称" }; GrdWidth = new int[] { 100, 200 }; //if (Convertor.IsNull(control.Tag.ToString(),"0")!="0") sfield = new string[] { "wbm", "pym", "", "", "" }; //else // sfield=new string[] {"","","","",""}; ssql = "select id,dwmc from yp_ypdw where id<>0 "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "药品单位"; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Text = row["dwmc"].ToString(); control.Tag = row["ID"].ToString(); } } if (_ShowCardType == ShowCardType.厂家) { GrdMappingName = new string[] { "id", "生产厂家", "拼音码", "五笔码" }; GrdWidth = new int[] { 0, 150, 100, 100 }; sfield = new string[] { "wbm", "pym", "", "", "" }; ssql = "select id,sccj,pym,wbm from yp_sccj where id<>0 "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "生产厂家"; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Text = row["sccj"].ToString(); control.Tag = row["id"].ToString(); } } if (_ShowCardType == ShowCardType.用法) { GrdMappingName = new string[] { "id", "使用方法", "拼音码", "五笔码" }; GrdWidth = new int[] { 0, 150, 100, 100 }; //if (Convertor.IsNull(control.Tag.ToString(),"0")!="0") sfield = new string[] { "wb_code", "py_code", "", "", "" }; //else // sfield=new string[] {"","","","",""}; ssql = "select id,name,py_code,wb_code from jc_usagediction where name is not null "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "药品用法"; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Text = row["name"].ToString(); control.Tag = row["id"].ToString(); } } if (_ShowCardType == ShowCardType.药理分类) { GrdMappingName = new string[] { "id", "货位编号", "药品分类", "父分类", "拼音码", "五笔码" }; GrdWidth = new int[] { 0, 60, 150, 150, 100, 100 }; // if (Convertor.IsNull(control.Tag.ToString(),"0")!="0") sfield = new string[] { "wbm", "pym", "", "", "" }; // else // sfield=new string[] {"","","","",""}; ssql = "select id,hwbh,flmc,(select flmc from yp_ylfl where id=a.fid),pym,wbm from yp_ylfl a where yjdbz=1 "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Width = 600; f.Text = "药理分类"; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Text = row["flmc"].ToString(); control.Tag = row["id"].ToString(); } } if (_ShowCardType == ShowCardType.供货单位) { GrdMappingName = new string[] { "id", "供货商", "拼音码", "五笔码" }; GrdWidth = new int[] { 0, 150, 100, 100 }; sfield = new string[] { "wbm", "pym", "", "", "" }; ssql = "select ID,ghdwmc,pym,wbm from yp_ghdw WHERE ID<>0 "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "供货单位"; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Text = row["ghdwmc"].ToString(); control.Tag = row["id"].ToString(); } } if (_ShowCardType == ShowCardType.包含在科室管理类型中的药品字典) { //SystemCfg cfg = new SystemCfg(8002, _DataBase); //string tablename = "YK_KCMX"; //if (cfg.Config == "1") string tablename = Yp.Seek_kcmx_table(deptid, _DataBase); GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "单位", "DWBL", "上次进价", "进货价", "批发价", "零售价", "货号", "基药" }; GrdWidth = new int[] { 0, 0, 0, 140, 90, 90, 30, 0, 70, 60, 60, 60, 100, 45 }; sfield = new string[] { "b.wbm", "b.pym", "szm", "ywm", "ypbm" }; ssql = @"select distinct top 100 a.ggid,a.cjid,0 rowno,s_yppm,s_ypgg,s_sccj,s_ypdw,1 dwbl, (case when scjj=0 or scjj is null then '' else cast(scjj as varchar(50)) end) scjj, a.mrjj, pfj,lsj,shh,(case when GJJBYW=1 then '是' else '' end) 基药 from vi_yp_ypcd a inner join yp_ypbm b " + " on a.ggid=b.ggid left join " + tablename + " c on a.cjid=c.cjid and c.deptid=" + deptid + " where cjbdelete=0 and a.n_ypzlx in(select ypzlx from yp_gllx where deptid=" + deptid + ") "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "药品输入"; f.Width = 800; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } if (_ShowCardType == ShowCardType.所有药品字典) { GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "单位", "DWBL", "批发价", "零售价", "货号" }; GrdWidth = new int[] { 0, 0, 0, 140, 90, 90, 30, 0, 70, 60, 60, 100 }; sfield = new string[] { "b.wbm", "b.pym", "szm", "ywm", "ypbm" }; ssql = "select distinct top 100 a.ggid,a.cjid,0 rowno,s_yppm,s_ypgg,s_sccj,s_ypdw,1 dwbl,pfj,lsj,shh from yp_ypcjd a inner join yp_ypbm b " + " on a.ggid=b.ggid "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "药品输入"; f.Width = 700; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } if (_ShowCardType == ShowCardType.库存批号列表) { GrdMappingName = new string[] { "行号", "库存量", "单位", "批号", "效期", "库位", "kwid" }; GrdWidth = new int[] { 0, 80, 40, 75, 100, 0, 0 }; sfield = new string[] { "", "", "", "", "" }; if (YpConfig.是否药库(deptid, _DataBase) == true) { ssql = "select 0, kcl,dbo.fun_yp_ypdw(zxdw),ypph,ypxq,'' kwmc,kwid from yk_kcph " + " where deptid=" + deptid + " and cjid=" + Fid + " and bdelete=0 "; } else { ssql = "select 0, kcl,dbo.fun_yp_ypdw(zxdw),ypph,ypxq,'' kwmc,kwid from yf_kcph " + " where deptid=" + deptid + " and cjid=" + Fid + " and bdelete=0 "; } f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, "", ssql, _DataBase); f.Location = point; f.Text = "批号列表"; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Text = row["ypph"].ToString(); } } if (_ShowCardType == ShowCardType.库存药品) { GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "库存", "单位", "DWBL", "批发价", "零售价", "货号" }; GrdWidth = new int[] { 0, 0, 30, 140, 90, 90, 60, 30, 0, 60, 60, 100 }; sfield = new string[] { "wbm", "pym", "szm", "ywm", "ypbm" }; /* * update code by pengy 7-2 10:17 * 按系统参数设置获取库存是否大于等于0的数据 */ ssql = "select config from jc_config where id = '8200'"; DataTable paramTable = _DataBase.GetDataTable(ssql); bool ypkc = paramTable != null && paramTable.Rows.Count > 0 && paramTable.Rows[0][0].ToString().Trim() == "1" ? true : false; if (YpConfig.是否药库(deptid, _DataBase) == true) { if (ypkc) { ssql = @"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL >= 0 and deptid=" + deptid + " and bdelete_kc=0 and a.cjid in (select cjid from YP_YPCJD where iswbyp =1)"; } else { ssql = @"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid=" + deptid + " and bdelete_kc=0 and a.cjid in (select cjid from YP_YPCJD where iswbyp =1)"; } } else { if (ypkc) { ssql = @"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl/dwbl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL >= 0 and deptid=" + deptid + " and bdelete_kc=0 and a.cjid in (select cjid from YP_YPCJD where iswbyp =1)"; } else { ssql = @"select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl/dwbl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid=" + deptid + " and bdelete_kc=0 and a.cjid in (select cjid from YP_YPCJD where iswbyp =1)"; } } f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql, _DataBase); f.Location = point; f.Text = "库存药品"; f.Width = 700; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } if (_ShowCardType == ShowCardType.库存药品_不区分禁用) { GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "库存", "单位", "DWBL", "批发价", "零售价", "货号" }; GrdWidth = new int[] { 0, 0, 30, 140, 90, 90, 60, 30, 0, 60, 60, 100 }; sfield = new string[] { "wbm", "pym", "szm", "ywm", "ypbm" }; if (YpConfig.是否药库(deptid, _DataBase) == true) { ssql = "select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid=" + deptid + " "; } else { ssql = "select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,cast(kcl/dwbl as float) kcl,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and KCL > 0 and deptid=" + deptid + " "; } f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql, _DataBase); f.Location = point; f.Text = "库存药品"; f.Width = 700; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } if (_ShowCardType == ShowCardType.库存药品_外用药品) { GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "单位", "DWBL", "批发价", "零售价", "货号" }; GrdWidth = new int[] { 0, 0, 30, 140, 90, 90, 30, 0, 60, 60, 100 }; sfield = new string[] { "wbm", "pym", "szm", "ywm", "ypbm" }; if (YpConfig.是否药库(deptid, _DataBase) == true) { ssql = "select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yK_kcmx a,yp_ypbm b where a.ggid=b.ggid and wyyp=1 and deptid=" + deptid + " and bdelete_kc=0 "; } else { ssql = "select distinct top 100 a.ggid,cjid,0 rowno,yppm,ypgg,s_sccj,s_ypdw,1 dwbl,pfj,lsj,shh from vi_yf_kcmx a,yp_ypbm b where a.ggid=b.ggid and wyyp=1 and deptid=" + deptid + " and bdelete_kc=0 "; } f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql, _DataBase); f.Location = point; f.Text = "外用药品"; f.Width = 700; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } #region 加工成品的药品字典 if (_ShowCardType == ShowCardType.加工成品的药品字典) { //SystemCfg cfg = new SystemCfg(8002, _DataBase); //string tablename = "YK_KCMX"; //if (cfg.Config == "1") string tablename = Yp.Seek_kcmx_table(deptid, _DataBase); GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "单位", "子类型", "DWBL", "上次进价", "批发价", "零售价", "货号", "基药" }; GrdWidth = new int[] { 0, 0, 0, 140, 90, 90, 30, 60, 0, 70, 60, 60, 100, 45 }; sfield = new string[] { "b.wbm", "b.pym", "szm", "ywm", "ypbm" }; string strWhere = ""; DataTable dtConfig = _DataBase.GetDataTable(string.Format(" select config from jc_config where id = 8042 ", 8042)); if (dtConfig.Rows.Count > 0) { string strCfg = dtConfig.Rows[0][0].ToString(); string[] strs = strCfg.Split('|'); string strCp = strs[0]; string[] scps = strCp.Split(','); for (int i = 0; i < scps.Length; i++) { if (i == 0) { strWhere += string.Format(" and a.n_ypzlx in ({0},", scps[i]); } else { strWhere += string.Format("{0},", scps[i]); } if (i == scps.Length - 1) { strWhere = (strWhere.Substring(0, strWhere.Length - 1)) + ") "; } } } ssql = "select distinct top 80 a.ggid,a.cjid,0 rowno,s_yppm,s_ypgg,s_sccj,s_ypdw, d.mc zlxmc, 1 dwbl,(case when scjj=0 or scjj is null then '' else cast(scjj as varchar(50)) end) scjj,pfj,lsj,shh,(case when GJJBYW=1 then '是' else '' end) 基药 from vi_yp_ypcd a inner join yp_ypbm b " + " on a.ggid=b.ggid left join " + tablename + " c on a.cjid=c.cjid and c.deptid=" + deptid + " inner join yp_ypzlx d on a.ypzlx=d.id where cjbdelete=0" + strWhere + " and a.n_ypzlx in(select ypzlx from yp_gllx where deptid=" + deptid + ") "; try { f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); } catch { throw new Exception(" 8042参数设置有误! "); return; } f.Location = point; f.Text = "药品输入"; f.Width = 750; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } #endregion #region 制剂成品的药品字典 if (_ShowCardType == ShowCardType.制剂成品的药品字典) { string tablename = Yp.Seek_kcmx_table(deptid, _DataBase); GrdMappingName = new string[] { "ggid", "cjid", "行号", "品名", "规格", "厂家", "单位", "子类型", "DWBL", "上次进价", "批发价", "零售价", "货号", "基药" }; GrdWidth = new int[] { 0, 0, 0, 140, 90, 90, 30, 60, 0, 70, 60, 60, 100, 45 }; sfield = new string[] { "b.wbm", "b.pym", "szm", "ywm", "ypbm" }; string strWhere = ""; ssql = "select distinct top 80 a.ggid,a.cjid,0 rowno,s_yppm,s_ypgg,s_sccj,s_ypdw, d.mc zlxmc, 1 dwbl,(case when scjj=0 or scjj is null then '' else cast(scjj as varchar(50)) end) scjj,pfj,lsj,shh,(case when GJJBYW=1 then '是' else '' end) 基药 from vi_yp_ypcd a inner join yp_ypbm b " + " on a.ggid=b.ggid left join " + tablename + " c on a.cjid=c.cjid and c.deptid=" + deptid + " inner join yp_ypzlx d on a.ypzlx=d.id where cjbdelete=0" + strWhere + " and a.n_ypzlx in(select ypzlx from yp_gllx where deptid=" + deptid + ") "; f = new Fshowcard(GrdMappingName, GrdWidth, sfield, FilterType.拼音, control.Text.Trim(), ssql); f.Location = point; f.Text = "药品输入"; f.Width = 750; f.ShowDialog(); DataRow row = f.dataRow; if (row != null) { control.Tag = row["cjid"].ToString(); } } #endregion }
//由盘存明细数量生成盘点明细 并插入单据 及单据明细 public static void Insert_dj_djmx_kcmx(Guid djid_pd, RelationalDatabase db, out Guid djid) { try { int day = -90; //盘盈逆推天数 string pcglfs = "0"; //批次管理方式 0-先进先出 1-效期优先 pcglfs = (new SystemCfg(8051)).Config; string ssql = string.Format(@" select * from yf_pd where id='{0}'", djid_pd); DataTable tbTemp = db.GetDataTable(ssql); if (tbTemp.Rows.Count <= 0) { throw new Exception("找不到盘存录入表"); } int deptid = Convert.ToInt32(tbTemp.Rows[0]["deptid"]);//科室id int uid = Convert.ToInt32(tbTemp.Rows[0]["djy"]); int jgbm = Convert.ToInt32(tbTemp.Rows[0]["jgbm"]); bool byk = YpConfig.是否药库(deptid, db);//是否药库 string strTbKcph = "yk_kcph"; string strTbKcmx = "yk_kcmx"; if (!byk) { strTbKcph = "yf_kcph"; strTbKcmx = "yf_kcmx"; } ssql = string.Format(@" select b.kcl,a.zcs*b.dwbl/a.ydwbl zcsl,a.pcs*b.dwbl/a.ydwbl pcsl, a.cjid,c.ggid,b.zxdw zxdw, dbo.fun_yp_ypdw(b.zxdw) ypdw,b.dwbl dwbl, c.shh,c.yppm,c.ypspm,c.ypgg, c.s_sccj sccj,c.pfj/b.dwbl pfj,c.lsj/b.dwbl lsj from YF_PDMX_KCMX a inner join {0} b on a.cjid=b.cjid inner join vi_yp_ypcd c on a.cjid=c.cjid inner join YF_PD d on d.ID=a.djid and d.deptid=b.deptid where a.djid='{1}' and d.deptid={2}", strTbKcmx, djid_pd, deptid); DataTable tb = db.GetDataTable(ssql); DataRow[] rows = tb.Select(" zcsl<>pcsl "); //DataRow[] rowsTemp = tb.Select(" ( zcsl-pcsl-kcl>0)");//帐存数量-盘存数量-库存量 //if ( rowsTemp.Length > 0 ) //{ // throw new Exception( "库存量小于盘亏数量" ); //} object objZcsl = tb.Compute("sum(zcsl)", ""); object objPcsl = tb.Compute("sum(pcsl)", ""); object objKcl = tb.Compute("sum(kcl)", ""); decimal yks = Convert.ToDecimal(Convertor.IsNull(objZcsl, "0")) - Convert.ToDecimal(Convertor.IsNull(objPcsl, "0")); decimal _kcl = Convert.ToDecimal(Convertor.IsNull(objKcl, "0")); if (yks < 0 && Math.Abs(yks) > _kcl) { throw new Exception("盘亏数大于当前库存量"); } #region 保存盘点盈亏单据头表 Guid _djid; string _err_text = ""; int _err_code = 0; string ywlx = "008"; DateTime serverTime = Convert.ToDateTime(db.GetDataResult(db.GetServerTimeString()).ToString()); decimal sumpfje = 0; //批发金额 decimal sumlsje = 0; //零售金额 decimal sumjhje = 0; //进货金额 long djh = Yp.SeekNewDjh(ywlx, deptid, db); //单据流水号 string sdjh = Yp.SeekNewDjh_Str(ywlx, deptid, db); if (byk) { Yk_dj_djmx.SaveDJ(Guid.Empty, djh, deptid, ywlx, deptid, 0, serverTime.ToShortDateString(), uid, serverTime.ToShortDateString(), serverTime.ToString(), "", "", "", "", 0, 0, sumjhje, sumpfje, sumlsje, sdjh, out _djid, out _err_code, out _err_text, jgbm, db); if (_err_code != 0) { throw new Exception("插入盈亏单据明细失败!" + _err_text); } } else { YF_DJ_DJMX.SaveDJ(Guid.Empty, djh, deptid, ywlx, deptid, 0, serverTime.ToShortDateString(), uid, serverTime.ToShortDateString(), serverTime.ToString(), "", "", "", "", 0, 0, sumjhje, sumpfje, sumlsje, out _djid, out _err_code, out _err_text, jgbm, db); if (_err_code != 0) { throw new Exception("插入盈亏单据明细失败!" + _err_text); } } #endregion #region 保存盘点盈亏单据明细表 for (int i = 0; i < rows.Length; i++) { DataRow row = rows[i]; string yppm = row["yppm"].ToString().Trim(); //品名 string ypspm = row["ypspm"].ToString().Trim(); //商品名 string ypgg = row["ypgg"].ToString().Trim(); //规格 int ggid = Convert.ToInt32(row["ggid"]); //ggid string sccj = row["sccj"].ToString(); //sccj decimal jhj = 0; //进货价 decimal pfj = Convert.ToDecimal(row["pfj"]); //批发价 decimal lsj = Convert.ToDecimal(row["lsj"]); //零售价 string ypph = ""; //批号 string ypxq = ""; //效期 string yppch = ""; //批次号 Guid kcid = Guid.Empty; //kcid decimal zcsl = Convert.ToDecimal(row["zcsl"]); //帐存数量 decimal pcsl = Convert.ToDecimal(row["pcsl"]); //盘存数量 int cjid = Convert.ToInt32(row["cjid"]); decimal slcz = zcsl - pcsl; int pxxh = 0; //排序序号 if (slcz > 0) //数量差值 大于0 帐存数>盘存数 盘亏 { #region 盘亏 if (pcglfs == "0")//先进先出 { ssql = string.Format(" select kcl,jhj,ypph,ypxq,yppch, id kcid from {0} where cjid={1} and deptid= {2} and kcl>0 order by djsj asc", strTbKcph, cjid, deptid); } if (pcglfs == "1") { ssql = string.Format(" select kcl,jhj,ypph,ypxq,yppch, id kcid from {0} where cjid={1} and deptid= {2} and kcl>0 order by ypxq asc", strTbKcph, cjid, deptid); } DataTable tbkcph = db.GetDataTable(ssql); for (int j = 0; j < tbkcph.Rows.Count; j++) { DataRow row1 = tbkcph.Rows[j]; decimal kcl = Convert.ToDecimal(row1["kcl"]); // decimal cks = 0; if (kcl >= slcz) { cks = slcz; slcz = 0; } else { cks = kcl; slcz -= cks; } ypph = row1["ypph"].ToString(); ypxq = row1["ypxq"].ToString(); yppch = row1["yppch"].ToString(); kcid = new Guid(row1["kcid"].ToString()); jhj = Convert.ToDecimal(row1["jhj"]); #region 保存单据明细 if (byk) { Yk_dj_djmx.SaveDJMX(Guid.Empty, _djid, cjid, 0, row["shh"].ToString(), yppm, ypspm, ypgg, sccj, ypph, ypxq, 0, 0, Convert.ToDecimal(cks * (-1)), row["ypdw"].ToString(), Convert.ToInt32(row["zxdw"]), //zxdw Convert.ToInt32(row["dwbl"]), //dwbl jhj, pfj, lsj, Convert.ToDecimal(jhj * cks * (-1)), Convert.ToDecimal(pfj * cks * (-1)), Convert.ToDecimal(lsj * cks * (-1)), djh, deptid, ywlx, "",//备注 "", 0, out _err_code, out _err_text, db, 0, yppch, kcid); if (_err_code != 0) { throw new Exception("插入单据明细失败!"); } } else { YF_DJ_DJMX.SaveDJMX(Guid.Empty, _djid, cjid, 0, row["shh"].ToString(), yppm, ypspm, ypgg, sccj, ypph, ypxq, 0, 0, Convert.ToDecimal(cks * (-1)), row["ypdw"].ToString(), Convert.ToInt32(row["zxdw"]),// Convert.ToInt32(row["dwbl"]), jhj, pfj, lsj, Convert.ToDecimal(jhj * cks * (-1)), Convert.ToDecimal(pfj * cks * (-1)), Convert.ToDecimal(lsj * cks * (-1)), djh, deptid, ywlx, "", "", out _err_code, out _err_text, db, pxxh, yppch, kcid); if (_err_code != 0) { throw new Exception("插入单据明细失败!"); } } #endregion sumjhje += Math.Round(Convert.ToDecimal(cks * jhj * (-1)), 3); sumpfje += Math.Round(Convert.ToDecimal(cks * pfj * (-1)), 3); sumlsje += Math.Round(Convert.ToDecimal(cks * lsj * (-1)), 3); if (slcz == 0) { break; } } if (slcz > 0) { throw new Exception("库存量小于盘亏数量"); } #endregion } else//帐存数<盘存数 盘盈 { #region 盘盈 string strOrder = ""; if (pcglfs == "0") { strOrder = " order by djsj desc "; } else { strOrder = " order by ypxq desc "; } string vi_name = "vi_yf_kcph"; string strYwlx = " ('001','002','003','004','009','015','016','019') "; string tbYwlx = "yf_ywlx"; string tbDjmx = "yf_djmx"; //药房业务:001-采购入库 002-采购退货 003-药品调出 004-药房退库 009-期初录入 // 015-药品调入 016-药库出库单 019-其他入库 if (byk) { vi_name = "vi_yk_kcph"; tbYwlx = "yk_ywlx"; tbDjmx = "yk_djmx"; strYwlx = " ('001','002') "; //药库业务: 001-采购入库 002-药品退货 } ssql = string.Format(@" select * from ( select sum(a.YPSL*m.DWBL/a.YDWBL*(case y.YWFX when '+' then 1 else -1 end) )-sum(m.kcl) kcl, m.jhj,m.ypph,m.ypxq,m.yppch,m.kcid,m.djsj_kc djsj from {6} a inner join {7} y on a.ywlx=y.YWLX inner join {3} m on m.cjid=a.CJID and a.KCID=m.KCID and a.deptid=m.deptid where a.YWLX in {5} and m.djsj_kc>DATEADD(day,{0},GETDATE()) and m.cjid={1} and m.deptid={2} group by m.jhj,m.ypph,m.ypxq,m.yppch,m.kcid,m.djsj_kc ,m.ypph,m.ypxq,m.yppch ) z where z.kcl > 0 {4}", day, cjid, deptid, vi_name, strOrder, strYwlx, tbDjmx, tbYwlx); DataTable tb_py = db.GetDataTable(ssql); decimal sysl = Convert.ToDecimal(slcz * (-1)); for (int j = 0; j < tb_py.Rows.Count; j++) { DataRow row_py = tb_py.Rows[j]; decimal kcl = Convert.ToDecimal(row_py["kcl"]); decimal cks = 0; ypph = row_py["ypph"].ToString(); yppch = row_py["yppch"].ToString(); ypxq = row_py["ypxq"].ToString(); kcid = new Guid(row_py["kcid"].ToString()); jhj = Convert.ToDecimal(row_py["jhj"]); if (kcl >= sysl) { cks = sysl; sysl -= cks; } else { cks = kcl; sysl -= kcl; } decimal sl = cks; #region 保存单据明细 if (byk) { Yk_dj_djmx.SaveDJMX(Guid.Empty, _djid, cjid, 0, row["shh"].ToString(), yppm, ypspm, ypgg, sccj, ypph, ypxq, 0, 0, sl, row["ypdw"].ToString(), Convert.ToInt32(row["zxdw"]), //zxdw Convert.ToInt32(row["dwbl"]), //ypdw jhj, pfj, lsj, Convert.ToDecimal(jhj * sl), Convert.ToDecimal(pfj * sl), Convert.ToDecimal(lsj * sl), djh, deptid, ywlx, "",//备注 "", 0, out _err_code, out _err_text, db, 0, yppch, kcid); } else { YF_DJ_DJMX.SaveDJMX(Guid.Empty, _djid, cjid, 0, row["shh"].ToString(), yppm, ypspm, ypgg, sccj, ypph, ypxq, 0, 0, sl, row["ypdw"].ToString(), Convert.ToInt32(row["zxdw"]),// Convert.ToInt32(row["dwbl"]), jhj, pfj, lsj, Convert.ToDecimal(jhj * sl), Convert.ToDecimal(pfj * sl), Convert.ToDecimal(lsj * sl), djh, deptid, ywlx, "", "", out _err_code, out _err_text, db, pxxh, yppch, kcid); } #endregion sumjhje += Math.Round(Convert.ToDecimal(jhj * sl), 3); sumpfje += Math.Round(Convert.ToDecimal(pfj * sl), 3); sumlsje += Math.Round(Convert.ToDecimal(lsj * sl), 3); ypph = row_py["ypph"].ToString(); yppch = row_py["yppch"].ToString(); ypxq = row_py["ypxq"].ToString(); kcid = new Guid(row_py["kcid"].ToString()); jhj = Convert.ToDecimal(row_py["jhj"]); if (sysl == 0) { break; } } if (sysl > 0) //存在未能分配的记录,用最新的批次 { ssql = string.Format(@" select top 1 a.kcl,a.jhj,a.ypph,a.ypxq,a.yppch,a.id kcid from {0} a where a.cjid={1} and a.deptid={2} {3} ", strTbKcph, cjid, deptid, strOrder); DataTable tb_sysl = db.GetDataTable(ssql); DataRow row_py = tb_sysl.Rows[0]; ypph = row_py["ypph"].ToString(); yppch = row_py["yppch"].ToString(); ypxq = row_py["ypxq"].ToString(); kcid = new Guid(row_py["kcid"].ToString()); jhj = Convert.ToDecimal(row_py["jhj"]); decimal sl = Convert.ToDecimal(sysl); #region 保存单据明细 if (byk) { Yk_dj_djmx.SaveDJMX(Guid.Empty, _djid, cjid, 0, row["shh"].ToString(), yppm, ypspm, ypgg, sccj, ypph, ypxq, 0, 0, sl, row["ypdw"].ToString(), Convert.ToInt32(row["zxdw"]), //zxdw Convert.ToInt32(row["dwbl"]), //ypdw jhj, pfj, lsj, Convert.ToDecimal(jhj * sl), Convert.ToDecimal(pfj * sl), Convert.ToDecimal(lsj * sl), djh, deptid, ywlx, "",//备注 "", 0, out _err_code, out _err_text, db, 0, yppch, kcid); } else { YF_DJ_DJMX.SaveDJMX(Guid.Empty, _djid, cjid, 0, row["shh"].ToString(), yppm, ypspm, ypgg, sccj, ypph, ypxq, 0, 0, sl, row["ypdw"].ToString(), Convert.ToInt32(row["zxdw"]),// Convert.ToInt32(row["dwbl"]), jhj, pfj, lsj, Convert.ToDecimal(jhj * sl), Convert.ToDecimal(pfj * sl), Convert.ToDecimal(lsj * sl), djh, deptid, ywlx, "", "", out _err_code, out _err_text, db, pxxh, yppch, kcid); } #endregion sumjhje += Math.Round(Convert.ToDecimal(jhj * sl), 3); sumpfje += Math.Round(Convert.ToDecimal(pfj * sl), 3); sumlsje += Math.Round(Convert.ToDecimal(lsj * sl), 3); } #region // if (pcglfs == "0")//先进先出 盘盈到最新的批次上 // { // } // else //效期优先 盘盈到效期最大的批次上 // { // ssql = string.Format(@" select top 1 a.kcl,a.jhj,a.ypph,a.ypxq,a.yppch,a.id kcid from {0} a // where a.cjid={1} and a.deptid={2} order by ypxq desc ", strTbKcph, cjid, deptid); // } // DataTable tbkcph = db.GetDataTable(ssql); // if (tbkcph.Rows.Count <= 0) // { // throw new Exception("找不到库存批次记录!"); // } // DataRow row1 = tbkcph.Rows[0]; // decimal cks = slcz; // ypph = row1["ypph"].ToString(); // ypxq = row1["ypxq"].ToString(); // yppch = row1["yppch"].ToString(); // kcid = new Guid(row1["kcid"].ToString()); // jhj = Convert.ToDecimal(row1["jhj"]); // #region 保存单据明细 // if (byk) // { // Yk_dj_djmx.SaveDJMX(Guid.Empty, _djid, cjid, 0, // row["shh"].ToString(), // yppm, ypspm, ypgg, sccj, // ypph, ypxq, 0, 0, // Convert.ToDecimal(cks*(-1)), // row["ypdw"].ToString(), // Convert.ToInt32(row["zxdw"]),//zxdw // Convert.ToInt32(row["dwbl"]),//ypdw // jhj, // pfj, // lsj, // Convert.ToDecimal(jhj * cks*(-1)), // Convert.ToDecimal(pfj * cks*(-1)), // Convert.ToDecimal(lsj * cks*(-1)), // djh, deptid, // ywlx, // "",//备注 // "", // out _err_code, // out _err_text, // db, 0, yppch, kcid); // } // else // { // YF_DJ_DJMX.SaveDJMX(Guid.Empty, _djid, cjid, 0, // row["shh"].ToString(), // yppm, ypspm, ypgg, sccj, // ypph, ypxq, 0, 0, // Convert.ToDecimal(cks*(-1)), // row["ypdw"].ToString(), // Convert.ToInt32(row["zxdw"]),// // Convert.ToInt32(row["dwbl"]) , // jhj, // pfj, // lsj, // Convert.ToDecimal(jhj * cks * (-1)), // Convert.ToDecimal(pfj * cks * (-1)), // Convert.ToDecimal(lsj * cks * (-1)), // djh, // deptid, ywlx, // "", // "", // out _err_code, // out _err_text, db, // pxxh, // yppch, // kcid); // } // #endregion // sumjhje += Math.Round(Convert.ToDecimal(cks * jhj*(-1)), 3); // sumpfje += Math.Round(Convert.ToDecimal(cks * pfj*(-1)), 3); // sumlsje += Math.Round(Convert.ToDecimal(cks * lsj*(-1)), 3); #endregion #endregion } } #endregion #region 回填盘点盈亏单据头表金额 if (byk) { ssql = string.Format(" update yk_dj set sumjhje={0} where id='{1}'", sumjhje, _djid); } else { ssql = string.Format(" update yf_dj set sumjhje={0} where id='{1}'", sumjhje, _djid); } if (db.DoCommand(ssql) <= 0) { throw new Exception("更新进货金额失败!"); } #endregion djid = _djid; } catch (Exception err) { throw new Exception(err.ToString()); } }