public int AddPacking(int DecoctingNum, string PackPer) { int end = 0; /// <summary> /// 添加包装信息 /// </summary> /// <param name="einfo"></param> /// <returns></returns> /// #region 当没有收到煎药完成指令和开始排液指令,触发判断煎药是否完成未完成将煎药时间设置为开始煎药时间+25MIN+煎药方案时间 try { //包装流程修改,若煎药流程结束,扫码开始包装,包装代数为实际代数+多包代数。 //多包代数 string str11 = "select top 1 package_machine_nums from dbo.tb_sys_add_setting"; SqlDataReader sr11 = db.get_Reader(str11); int more_num = 0; if (sr11.Read()) { more_num = Convert.ToInt32(sr11["package_machine_nums"].ToString()); // string sql12 = "update prescription set packagenum =packagenum+" + more_num.ToString() + " where id = '" + DecoctingNum.ToString().Trim() + "'";//+" and "+"'"++"'"; // db.cmd_Execute(sql12); string sql13 = "update tisaneinfo set tisanestatus ='1' where pid ='" + DecoctingNum.ToString().Trim() + "'"; db.cmd_Execute(sql13); } sr11.Close(); db.sp_Execute_no_return("sp_auto_tisane", DecoctingNum); } catch { end = 0; } #endregion String sql = ""; string per = PackPer.Substring(6); string employeeid = ""; string str7 = "select id from employee where EmNumAName ='" + PackPer + "'"; SqlDataReader sr7 = db.get_Reader(str7); if (sr7.Read()) { employeeid = sr7["id"].ToString(); } string str = "select pid from tisaneinfo where tisanestatus = 1 and pid = '" + DecoctingNum + "'"; //and pid not in (select pid from InvalidPrescription) SqlDataReader sr = db.get_Reader(str); System.DateTime now = new System.DateTime(); now = System.DateTime.Now; #region if 1 if (sr.Read()) { string result = sr["pid"].ToString(); int a = Convert.ToInt32(result); string str1 = "select * from Packing where DecoctingNum = '" + a + "'"; SqlDataReader sr1 = db.get_Reader(str1); #region 是否包装判断 if (sr1.Read()) { string start = "select Starttime from Packing where DecoctingNum = '" + a + "'"; SqlDataReader starttime = db.get_Reader(start); string starttime2 = ""; if (starttime.Read()) { string tate = "select Fpactate from Packing where DecoctingNum = '" + a + "'"; SqlDataReader tate1 = db.get_Reader(tate); if (tate1.Read()) { if (tate1["Fpactate"].ToString() == "0") { starttime2 = starttime["Starttime"].ToString(); //获取包装时间 DateTime starttime1 = Convert.ToDateTime(starttime2); //开始时间 string now1 = now.ToString("yyyy-MM-dd HH:mm:ss"); DateTime d3 = Convert.ToDateTime(now1); //把当前时间转变为datetime TimeSpan d4 = d3.Subtract(starttime1); //开始时间-当前时间 int fpack = Convert.ToInt32(d4.Days.ToString()) * 24 * 60 + Convert.ToInt32(d4.Hours.ToString()) * 60 + Convert.ToInt32(d4.Minutes.ToString()); //差值转换为分钟数 string packtime = fpack.ToString(); //sql = "INSERT INTO [Packing](DecoctingNum,packtime,Fpactate) VALUES('" + a + "','" + fpack + "','" + 2 + "')"; sql = "Update Packing set PacTime='" + now + "', Fpactate ='1' where DecoctingNum = '" + a + "'"; if (db.cmd_Execute(sql) == 1) { string sql1 = "update prescription set curstate = '包装完成' where id = '" + a + "'"; if (db.cmd_Execute(sql1) == 1) { string sql2 = "INSERT INTO [Delivery](DecoctingNum,Sendstate) VALUES('" + a + "','0')"; if (db.cmd_Execute(sql2) == 1) { string str5 = "select machineid from tisaneunit where pid = '" + DecoctingNum + "'"; SqlDataReader sr01 = db.get_Reader(str5); if (sr01.Read()) { string machineid = sr01["machineid"].ToString(); //更改包装机状态 string sq6 = "select unitnum from machine where id = '" + machineid + "'"; SqlDataReader sr6 = db.get_Reader(sq6); if (sr6.Read()) { string unitnum = sr6["unitnum"].ToString(); string sq7 = "update machine set status ='空闲' where unitnum = '" + unitnum + "' and mark =1"; db.cmd_Execute(sq7); } } } } } } else { sql = ""; } } } } #endregion #region 未开始包装判断 else { string sql2 = "INSERT INTO [Packing](DecoctingNum,Starttime,Fpactate,Pacpersonnel,employeeid) VALUES('" + a + "','" + now + "','" + 0 + "','" + per + "','" + employeeid + "')"; //开始包装 BaseInfo.Insert_PackCmd(now, db, DecoctingNum.ToString()); //SqlDataReader tate13 = db.get_Reader(sql2); if (db.cmd_Execute(sql2) == 1) { sql = "update prescription set doperson ='" + per + "',curstate = '开始包装' where id = '" + a + "'"; db.cmd_Execute(sql); // sql = "update prescription set doperson ='" + per + "',curstate = '开始包装' where id = '" + a + "'"; //db.cmd_Execute(sql2); //把机组表里的包装状态设为1 string now1 = now.ToString("yyyy-MM-dd HH:mm:ss"); DateTime d3 = Convert.ToDateTime(now1);//把当前时间转变为datetime sql = "update tisaneunit set packstatus = 1,endDate ='" + d3 + "' where pid ='" + a + "'"; db.cmd_Execute(sql); //更改煎药机状态为空闲 //string changetisanestatu = "update machine set status ='空闲' where id = (select machineid from tisaneunit where pid = '"+a+"')"; // db.cmd_Execute(changetisanestatu); //更改包装机状态为忙碌 // string changepackstatu = "update machine set status ='忙碌' where id = (select machineid from tisaneunit where pid = '" + a + "')"; // db.cmd_Execute(changepackstatu); string machineid = ""; string unitnum = ""; string str5 = "select machineid from tisaneunit where pid = '" + DecoctingNum + "'"; SqlDataReader sr5 = db.get_Reader(str5); if (sr5.Read()) { machineid = sr5["machineid"].ToString(); //更改包装机状态 string sq6 = "select unitnum from machine where id = '" + machineid + "'"; SqlDataReader sr6 = db.get_Reader(sq6); if (sr6.Read()) { unitnum = sr6["unitnum"].ToString(); string sq7 = "update machine set status ='忙碌' where unitnum = '" + unitnum + "'and mark =1"; db.cmd_Execute(sq7); } } string sql9 = "update machine set status ='空闲' where id = '" + machineid + "'"; db.cmd_Execute(sql9); } } #endregion } #endregion else { sql = ""; } if (sql == "") { end = 0; } else { // end = db.cmd_Execute(sql); end = 1; } return(end); }