public DrugCount getCacheDrug(Drug drug) { int index = findDrug(drug); if (index == -1) { return null; } return presc.drugCountList[index]; }
private void addDrug(Drug drug, int count) { int index = findDrug(drug); if (index != -1) { presc.drugCountList[index].count += count; presc.drugCountList[index].drug = drug; } else { DrugCount drugCount = new DrugCount(presc, drug, count); presc.drugCountList.Add(drugCount); } drugListToTable(); }
public bool updateDrug(Drug drug) { String queryCmd = "select * from drug where id = '" + drug.id + "'"; bool exist = db.queryDataTable(queryCmd).Rows.Count == 1; String cmd = "insert into drug values ('" + drug.id + "', '" + drug.name + "', '" + drug.price + "', '" + drug.type + "', '" + drug.comment + "', '" + drug.count + "')"; if (exist) { cmd = "update drug set name = '" + drug.name + "', price = '" + drug.price + "', type = '" + drug.type + "', count = '" + drug.count + "', comment = '" + drug.comment + "' where id = '" + drug.id + "'"; } return db.update(cmd); }
public Drug getDrugById(String id) { DataTable table = db.queryDataTable("select id, name, price, type, comment, count from drug where id = '" + id + "'"); if (table.Rows.Count == 0) { return null; } DataRow row = table.Rows[0]; Drug drug = new Drug(); drug.id = row.Field<String>("id"); drug.name = row.Field<String>("name"); drug.price = row.Field<Single>("price").ToString(); drug.type = row.Field<String>("type"); drug.comment = row.Field<String>("comment"); drug.count = row.Field<int>("count"); return drug; }
private void btnRegisterConfirm_Click(object sender, EventArgs e) { bool addDrug = this.chkAdd.Checked; String id = this.txtID.Text; String name = this.txtName.Text; String price = this.txtPrice.Text; String type = this.cbType.Text; String comment = this.txtComment.Text; String count = this.txtCount.Text; if (!checkInput(name, id, price, type, count, addDrug)) { MessageBox.Show("药品信息登记错误!"); return; } if (addDrug) { if (!drugDAO.addDrug(id, Convert.ToInt32(count))) { MessageBox.Show("药品入库失败!"); return; } } else { Drug drug = new Drug(id, name, price, type,Convert.ToInt32(count), comment); if (!drugDAO.updateDrug(drug)) { MessageBox.Show("药品信息登记失败!"); return; } } this.DialogResult = DialogResult.OK; this.Close(); }
public DrugCount(Presc presc, Drug drug, int count) { this.presc = presc; this.drug = drug; this.count = count; }
private int findDrug(Drug drug) { for (int i = 0; i < presc.drugCountList.Count; i++) { if (presc.drugCountList[i].drug.id == drug.id) { return i; } } return -1; }
private void btnRegisterConfirm_Click(object sender, EventArgs e) { int index = -1; if (gvDrug.CurrentRow == null || (index = gvDrug.CurrentRow.Index) < 0) { MessageBox.Show("请选择药品信息"); return; } DataGridViewRowCollection rows = gvDrug.Rows; String id = rows[index].Cells[0].Value.ToString(); String number = this.txtNumber.Text; if (!Regex.IsMatch(number, @"^([0-9]{1,})$", RegexOptions.IgnoreCase)) { MessageBox.Show("请输入使用药品数量"); return; } int count = Convert.ToInt32(number); Drug drug = drugDAO.getDrugById(id); int total = Convert.ToInt32(drug.count); DrugCount drugCount = parentWindow.getCacheDrug(drug); int selected = (drugCount != null ? drugCount.count : 0); if (selected + count > total || count <= 0) { MessageBox.Show("药品数量不合法:已选择 = " + selected + ", 待选择 = " + count + ", 库存 = " + total); return; } this.drug = drug; this.count = count; this.DialogResult = DialogResult.OK; this.Close(); }