//出药 private void btOut_Click(object sender, RoutedEventArgs e) { Cursor = Cursors.Wait; if (lvOut.Items.Count > 0) { PLC_Tcp_AP.MovePos type = PLC_Tcp_AP.MovePos.Top; switch (cbOutPosition.SelectedIndex) { case 1: type = PLC_Tcp_AP.MovePos.Up; break; case 2: type = PLC_Tcp_AP.MovePos.Down; break; } DataTable dtTemp = new DataTable(); dtTemp.Columns.Add("PosCode"); dtTemp.Columns.Add("Num"); OutPos[] ops = lvOut.ItemsSource as OutPos[]; foreach (OutPos op in ops) { DataRow row = dtTemp.NewRow(); row[0] = op.PosCode; row[1] = op.Num; dtTemp.Rows.Add(row); } dtTemp.DefaultView.Sort = "PosCode"; DataTable dtOut = dtTemp.DefaultView.ToTable(); OutDrug_AP od = new OutDrug_AP(type, dtOut, false, "", 0, null); od.GoOut(); Thread.Sleep(3000); while (OutDrug_AP.IsOut) { Thread.Sleep(500); } //lvOut.ItemsSource = null; ShowDrug(tbCode.Text.Trim()); Cursor = null; } }
//出药 private void GoOut() { if (!IsOut) { IsOut = true; string wins = GetWins(Config.Soft.MacCode); string sql = "select top 1 prescno,windowno,patname from pat_prescinfo where windowno in ({0}) and doflag in('W','D') and paytime>=convert(varchar(100),getdate(),23) order by toptime desc,paytime"; sql = string.Format(sql, wins); DataTable dtDoing; csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dtDoing); if (dtDoing.Rows.Count > 0) { string prescNo = dtDoing.Rows[0]["prescno"].ToString(); string windowNo = dtDoing.Rows[0]["windowno"].ToString(); string patname = dtDoing.Rows[0]["patname"].ToString(); //正在出药(D) UpdatePrescStatus(prescNo, "D"); //快发内药品明细 sql = @"select pd.drugonlycode,sum(drugnum) as num,drugunit,drugpacknum,drugpackunit,drugsplitnum,drugsplitunit from pat_druginfo pd left join drug_info di on di.drugonlycode=pd.drugonlycode where prescno='{0}' and pd.drugonlycode in ( select drugonlycode from drug_pos where maccode='{1}' ) group by pd.drugonlycode,drugunit,drugpacknum,drugpackunit,drugsplitnum,drugsplitunit"; sql = string.Format(sql, prescNo, Config.Soft.MacCode); DataTable dtDrug; csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dtDrug); if (dtDrug != null && dtDrug.Rows.Count > 0)//分配批次 { int pc = 1; int pcNum = Config.Mac_A.PCNum; foreach (DataRow dr_Drug in dtDrug.Rows) { string drugonlycode = dr_Drug["drugonlycode"].ToString().Trim(); int drugnum = GetNumInt(int.Parse(dr_Drug["num"].ToString().Trim()), dr_Drug["drugunit"].ToString().Trim(), int.Parse(dr_Drug["drugpacknum"].ToString().Trim()), dr_Drug["drugpackunit"].ToString().Trim()); if (drugnum > 0) { if (drugnum > Config.Mac_A.MaxNum)//超出出药上限(B) { UpdateDrugStatus(prescNo, drugonlycode, "B"); } else { sql = @"select sum(isnull(drugnum,0)-isnull(drugnummin,0)) num from drug_pos where maccode='{0}' and drugonlycode='{1}' and errorNum<3 group by drugonlycode"; sql = string.Format(sql, Config.Soft.MacCode, drugonlycode); int numSum = 0; string value; csSql.ExecuteScalar(sql, Config.Soft.ConnString, out value); if (!string.IsNullOrEmpty(value)) { numSum = int.Parse(value); } if (numSum < drugnum)//缺药(S) { UpdateDrugStatus(prescNo, drugonlycode, "S"); } else { if (drugnum > pcNum) { pc++; pcNum = Config.Mac_A.PCNum - drugnum; } else { pcNum -= drugnum; } //分配批次 sql = "update pat_druginfo set outpc={0},pcflag='N' where prescno='{1}' and drugonlycode='{2}'"; sql = string.Format(sql, pc, prescNo, drugonlycode); csSql.ExecuteSql(sql, Config.Soft.ConnString); } } } else { //机外 UpdateDrugStatus(prescNo, drugonlycode, "E"); } } //判断出药口位置 PLC_Tcp_AP.MovePos type = PLC_Tcp_AP.MovePos.Down; sql = "select outposition from sys_window_mac where windowno={0} and maccode='{1}'"; sql = string.Format(sql, windowNo, Config.Soft.MacCode); string v; csSql.ExecuteScalar(sql, Config.Soft.ConnString, out v); switch (v) { case "T": type = PLC_Tcp_AP.MovePos.Top; break; case "U": type = PLC_Tcp_AP.MovePos.Up; break; case "D": type = PLC_Tcp_AP.MovePos.Down; break; } //逐个批次出药 for (int p = 1; p <= pc; p++) { while (OutDrug_AP.IsOut) { Thread.Sleep(500); } sql = @"select drugonlycode,sum(drugnum) as num from pat_druginfo where prescno='{0}' and outpc='{1}' and drugonlycode in ( select drugonlycode from drug_pos where maccode='{2}' ) group by drugonlycode"; sql = string.Format(sql, prescNo, p, Config.Soft.MacCode); DataTable dtPC; csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dtPC); if (dtPC != null && dtPC.Rows.Count > 0) { DataTable dtOut = GetOutPos(dtPC); OutDrug_AP od = new OutDrug_AP(type, dtOut, true, prescNo, p, dtPC); od.GoOut(); //批次出药开始 sql = "update pat_druginfo set pcflag='D',dotime=getdate() where prescno='{0}' and outpc='{1}'"; sql = string.Format(sql, prescNo, p); csSql.ExecuteSql(sql, Config.Soft.ConnString); Thread.Sleep(1000); } Thread.Sleep(1000); while (OutDrug_AP.IsOut) { Thread.Sleep(500); } //批次出药完成 sql = "update pat_druginfo set pcflag='Y',dotime=getdate() where prescno='{0}' and outpc='{1}'"; sql = string.Format(sql, prescNo, p); csSql.ExecuteSql(sql, Config.Soft.ConnString); Thread.Sleep(1000); } } //结束出药(4) UpdatePrescStatus(prescNo, "O"); isWait = true; wait = Config.Mac_A.PrescWait; timer_Wait.Start(); IsOut = false; } IsOut = false; } }