public static int AddOrder(String patientNum, String useNum, String doctorNum, String orderNum, int type, String use_time) { String useName; Decimal price; if (type == 2) { price = (Decimal)DatabaseTool.ExeclSqlReturnItem(String.Format(SELECT_OPERATION_PRICE_BYID, useNum), "single_price"); useName = (String)DatabaseTool.ExeclSqlReturnItem(String.Format("select * from operation where o_num =\"{0}\"", useNum), "o_name"); } else if (type == 3) { price = (Decimal)DatabaseTool.ExeclSqlReturnItem(String.Format(SELECT_DEVICE_PRICE_BYID, useNum), "single_price"); useName = (String)DatabaseTool.ExeclSqlReturnItem(String.Format("select * from device where d_num =\"{0}\"", useNum), "d_name"); } else { return(-1); } if (DatabaseTool.ExecSql(String.Format(INSERT_ORDER_SQL, patientNum, useNum, 1, doctorNum, orderNum, type, System.DateTime.Now.ToString(), use_time, price, useName, 0))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } }
//插入医嘱 public static int InsertDoctorsAdvice(String doctorNum, String patientNum, String content, int type, String doctorName) { if (DatabaseTool.ExecSql(String.Format(INSERT_DOCTORSADVICE_SQL, doctorNum, patientNum, System.DateTime.Now.ToString(), content, type, doctorName))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } }
//函数二用于插入药品订单 //函数二需要传入 患者编号、药品编号、数量、医生的编号、订单编号、类型(用于区分三类操作:药品是1 手术是2 检查是3) public static int AddOrder(String patientNum, String useNum, int amount, String doctorNum, String orderNum, int type) { String useName = (String)DatabaseTool.ExeclSqlReturnItem(String.Format("select * from medicine where m_num =\"{0}\"", useNum), "m_name"); Decimal price = (Decimal)DatabaseTool.ExeclSqlReturnItem(String.Format(SELECT_MEDICINE_PRICE_BYID, useNum), "price"); price *= amount; if (DatabaseTool.ExecSql(String.Format(INSERT_ORDER_SQL, patientNum, useNum, amount, doctorNum, orderNum, type, System.DateTime.Now.ToString(), "", price, useName, 0))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } }
//添加设备 public static int AddDevice(String deviceNum, String deviceName, String manufacter, Decimal single_price, String dep_num) { if (DatabaseTool.ExeclSqlReturnItem(string.Format(QUERY_DEVICE_SQL, deviceNum), "d_name").ToString().Equals("-1") == false) { return(-1); } if (DatabaseTool.ExecSql(String.Format(INSERT_DEVICE_SQL, deviceNum, deviceName, manufacter, single_price, dep_num))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } }
//添加药品 public static int AddMedicine(String medNum, String medName, String manufactor, Decimal price, Int32 amount, String type) { if (DatabaseTool.ExeclSqlReturnItem(string.Format(QUERY_MEDICINE_SQL, medNum), "m_name").ToString().Equals("-1") == false) { return(-1); } if (DatabaseTool.ExecSql(String.Format(INSERT_MEDICINE_SQL, medNum, medName, manufactor, price, amount, type))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } }
//添加病房 public static int AddRoom(String roomNum, String location, String departNum) { if (DatabaseTool.ExeclSqlReturnItem(string.Format(QUERY_ROOM_SQL, roomNum), "r_num").ToString().Equals("-1") == false) { return(-1); } if (DatabaseTool.ExecSql(String.Format(INSERT_ROOM_SQL, roomNum, location, departNum))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } }
//添加用户 public static int AddUsers(String UserNum, String UserName, int type, String password, String sex, int age, String tel, String departNum) { if (DatabaseTool.ExeclSqlReturnItem(string.Format(QUERY_USERS_SQL, UserNum), "u_name").ToString().Equals("-1") == false) { return(-1); } if (DatabaseTool.ExecSql(String.Format(INSERT_USERS_SQL, UserNum, UserName, type, password, sex, age, tel, departNum))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } }
// 将患者出院未出院字段改为已经出院,返回病人信息和费用 public static LeaveInformation LeaveHospital(String ID) { DatabaseTool.ExecSql(String.Format(UPDATE_PATIENT_CONDITION, ID)); //更新患者状态为已出院 DatabaseTool.ExecSql(String.Format(UPDATE_DISCHARGE_TIME, System.DateTime.Now.ToString(), ID)); //插入病人出院时间 //全部订单存放至orders List <Dictionary <String, Object> > sqlResult1 = DatabaseTool.ExecSqlReturn(String.Format(SELECT_ALL_ORDERS_BY_ID, ID)); List <Order> orders = new List <Order>(); foreach (Dictionary <String, Object> dic in sqlResult1) //遍历结果集,每一条都加入list { orders.Add(Order.CreateOrder(dic)); } //获取入院时间与出院时间,计算时间差 DateTime admissionTime = Convert.ToDateTime(DatabaseTool.ExeclSqlReturnItem(String.Format(SELECT_PATIENT_BY_ID, ID), "admission_time")); DateTime dischargeTime = Convert.ToDateTime(DatabaseTool.ExeclSqlReturnItem(String.Format(SELECT_PATIENT_BY_ID, ID), "discharge_time")); TimeSpan ts = dischargeTime.Subtract(admissionTime).Duration(); String dateDiff = ts.Days.ToString() + "天"; //获取全部医嘱存放至advices List <DoctorsAdvice> advices = new List <DoctorsAdvice>(); List <Dictionary <String, Object> > sqlResult2 = DatabaseTool.ExecSqlReturn(String.Format(SELECT_ALL_ADVICES_BY_ID, ID)); foreach (Dictionary <String, Object> dic in sqlResult2) //遍历结果集,每一条都加入list { advices.Add(DoctorsAdvice.CreateDoctorsAdvice(dic)); } //计算最终费用存放至totalPrice Decimal totalPrice = DatabaseTool.ExeclSqlDecimal(String.Format(SELECT_ALL_PRICE, ID)); //获取用户部分信息 PatientPartInformation partInformation = new PatientPartInformation(); List <Dictionary <String, Object> > sqlResult3 = DatabaseTool.ExecSqlReturn(String.Format(SELECT_PATIENT_BY_ID, ID)); foreach (Dictionary <String, Object> dic in sqlResult3) //遍历结果集,每一条都加入list { partInformation = PatientPartInformation.CreatePatientInformation(dic); } //新建信息对象,返回 LeaveInformation information = LeaveInformation.CreateLeavelInformation(advices, dateDiff, orders, totalPrice, partInformation); return(information); }
//插入取药记录 public static int AddFetchRecords(List <FetchRecords> fetchRecords) { for (int i = 0; i < fetchRecords.Count; i++) { int nowAmout = Convert.ToInt32(DatabaseTool.ExeclSqlReturnItem(String.Format("select * from medicine", fetchRecords[i].MedcineNum), "amount")); nowAmout = nowAmout - fetchRecords[i].Amount; if (nowAmout < 0) { return(-1); } else { DatabaseTool.ExecSql(String.Format(INSERT_FETCHRECORDS_SQL, fetchRecords[i].Person, fetchRecords[i].medName, fetchRecords[i].PatientName, fetchRecords[i].Amount, fetchRecords[i].PatientNum, fetchRecords[i].FetchTime)); DatabaseTool.ExecSql(String.Format(UPDATE_MEDICINE_AMOUNT_SQL, nowAmout, fetchRecords[i].MedcineNum)); DatabaseTool.ExecSql(String.Format("update orders set isfetch=1 where order_num =\"{0}\" ", fetchRecords[i].OrderNum)); } } return(1); }
//执行插入操作 public static int AddPatient(Patient patient) { //根据病人id查找病人名字,如果找到病人名字,说明有对应id的记录(因为名字不能为空),说明输入的病人id无效 if (DatabaseTool.ExeclSqlReturnItem(string.Format(SELECT_PATIENT_BY_ID, patient.Id), "p_name").ToString().Equals("-1") == false) { return(-1); } else { System.Diagnostics.Debug.Write(String.Format(INSERT_PATIENT_SQL, patient.Id, patient.Name, patient.Sex, patient.Age, patient.Tel, patient.Department, patient.DrugAllergy, patient.MedicalHistory, patient.RoomNum, patient.BedNum, patient.PhysicanNum, patient.AdmissionTime, "", patient.IDNum, patient.BirthDate, patient.Nation, patient.Country, patient.Marriage, patient.Occupation, patient.NativePlace, patient.BirthPlace, patient.Address, patient.WorkingPlace, patient.WorkingTel, patient.Diagonse, 1)); if (DatabaseTool.ExecSql(String.Format(INSERT_PATIENT_SQL, patient.Id, patient.Name, patient.Sex, patient.Age, patient.Tel, patient.Department, patient.DrugAllergy, patient.MedicalHistory, patient.RoomNum, patient.BedNum, patient.PhysicanNum, patient.AdmissionTime, "", patient.IDNum, patient.BirthDate, patient.Nation, patient.Country, patient.Marriage, patient.Occupation, patient.NativePlace, patient.BirthPlace, patient.Address, patient.WorkingPlace, patient.WorkingTel, patient.Diagonse, 1))) { DatabaseTool.ExecSql(String.Format(UPDATE_BED_CONDITION, patient.BedNum)); return(DatabaseTool.GetLastInsertId()); } else { return(-1); } } }
public static int AddDepartment(String departNum, String departName, String departManager) { //先检查插入的科室编号是否重复,如果重复返回失败-1 String result = DatabaseTool.ExeclSqlReturnItem(string.Format(QUERY_DEPARTMENT_SQL, departNum), "d_name").ToString(); if (result.Equals("-1") == false) { return(-1); } else { if (DatabaseTool.ExecSql(String.Format(INSERT_DEPARTMENT_SQL, departNum, departName, departManager))) { return(DatabaseTool.GetLastInsertId()); } else { return(-1); } } }
//更新病房信息 public static bool UpdateRoom(String location, String departNum, String roomNum) { return(DatabaseTool.ExecSql(String.Format(UPDATE_ROOM_SQL, location, departNum, roomNum))); }
//更新用户 // "update users set u_name=\"{0}\",type={1},password=\"{2}\",sex=\"{3}\",age={4},tel=\"{5}\",dep_num=\"{6}\" where u_num=\"{7}\" "; public static bool UpdateUser(String UserName, int type, String password, String sex, int age, String tel, String departNum, String UserNum) { return(DatabaseTool.ExecSql(String.Format(UPDATE_USERS_SQL, UserName, type, password, sex, age, tel, departNum, UserNum))); }
//根据病房号删除病房 public static bool DeleteRoom(String roomNum) { return(DatabaseTool.ExecSql(String.Format(DELETE_ROOM_SQL, roomNum))); }
//根据设备号删除药品 public static bool DeleteDevice(String deviceNum) { return(DatabaseTool.ExecSql(String.Format(DELETE_DEVICE_SQL, deviceNum))); }
//更新设备信息 // private const String UPDATE_DEVICE_SQL = "update device set d_name=\"{1}\" ,manufacter=\"{2}\", single_price={3} dep_num=\"{5}\" where d_num="\{5}\" "; public static bool UpdateDevice(String deviceName, String manufacter, Decimal singlePrice, String departNum, String deviceNum) { return(DatabaseTool.ExecSql(String.Format(UPDATE_DEVICE_SQL, deviceName, manufacter, singlePrice, departNum, deviceNum))); }
//根据药品号删除药品 public static bool DeleteMedicine(String medNum) { return(DatabaseTool.ExecSql(String.Format(DELETE_MEDICINE_SQL, medNum))); }
//更新药品信息 public static bool UpdateMedicine(String medName, String manufactor, Decimal price, int amount, String type, String medNum) { // private const String UPDATE_MEDICINE_SQL = "update medicine set m_name=\"{1}\" manufactor=\"{2}\" price={3} amount={4} type=\"{5}\" where m_num=\"{5}\" "; System.Diagnostics.Debug.Write(String.Format(UPDATE_MEDICINE_SQL, medName, manufactor, price, amount, type, medNum)); return(DatabaseTool.ExecSql(String.Format(UPDATE_MEDICINE_SQL, medName, manufactor, price, amount, type, medNum))); }
//根据用户号删除用户 public static bool DeleteUser(String UserNum) { return(DatabaseTool.ExecSql(String.Format(DELETE_USERS_SQL, UserNum))); }
//更新科室 public static bool UpdateDepartment(String departName, String departManager, String departNum) { return(DatabaseTool.ExecSql(String.Format(UPDATE_DEPARTMENT_SQL, departName, departManager, departNum))); }
//根据科室号删除科室 public static bool DeleteDepartment(String departNum) { return(DatabaseTool.ExecSql(String.Format(DELETE_DEPARTMENT_SQL, departNum))); }