private void btn_save_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(txt_name.Text.Trim())) { XtraMessageBox.Show("请您输入药品名称!"); return; } var entity = new Domain.Model.Medicine() { Id = detailId, Name = txt_name.Text.Trim(), NameCode = Pinyin.GetInitials(Pinyin.ConvertEncoding(txt_name.Text.Trim(), Encoding.UTF8, Encoding.GetEncoding("GB2312")), Encoding.GetEncoding("GB2312"))?.ToLower(), CommonName = txt_commonName.Text.Trim(), CommonNameCode = string.IsNullOrWhiteSpace(txt_commonName.Text.Trim()) ? "" : Pinyin.GetInitials(Pinyin.ConvertEncoding(txt_commonName.Text.Trim(), Encoding.UTF8, Encoding.GetEncoding("GB2312")), Encoding.GetEncoding("GB2312"))?.ToLower(), JYFWId = lue_ssjyfw.EditValue == null ? 0 : int.Parse(lue_ssjyfw.EditValue.ToString()), BZGG = txt_bzgg.Text.Trim(), UnitId = lue_unit.EditValue == null ? 0 : int.Parse(lue_unit.EditValue.ToString()), TypeId = lue_type.EditValue == null ? 0 : int.Parse(lue_type.EditValue.ToString()), JGFLId = lue_jgfl.EditValue == null ? 0 : int.Parse(lue_jgfl.EditValue.ToString()), SupplierId = lue_gys.EditValue == null ? 0 : int.Parse(lue_gys.EditValue.ToString()), SCCJId = lue_sccj.EditValue == null ? 0 : int.Parse(lue_sccj.EditValue.ToString()), CPZC = txt_cpzc.Text.Trim(), PZWH = date_pzwh.Text.Trim(), IsPrescription = ckb_isPrescription.Checked, Status = 1, }; using (var db = SugarDao.GetInstance()) { if (Convert.ToBoolean(db.InsertOrUpdate(entity))) { string msg = detailId > 0 ? $"【修改成功】 " : $"【新增成功】"; Log.Info(new LoggerInfo() { LogType = LogType.药品信息.ToString(), CreateUserId = UserInfo.Account, Message = msg + $"药品Id:{entity.Id},药品名称:{entity.Name},药品简写:{entity.NameCode},药品通用名称:{entity.CommonName}" + $",药品通用名称简写:{entity.CommonNameCode},经营范围:{lue_ssjyfw.Text},药品规格:{txt_bzgg.Text},药品单位:{lue_unit.Text}" + $",药剂分类:{lue_type.Text},监管分类:{lue_jgfl.Text},供应商:{lue_gys.Text},生产厂家:{lue_sccj.Text},产品注册证批件号:{txt_cpzc.Text.Trim()}" + $",批准文号有效期:{ date_pzwh.Text.Trim()},是否处方药:{(entity.IsPrescription ? "是" : "否")}" }); DialogResult = DialogResult.OK; this.Close(); } else { DialogResult = DialogResult.Cancel; } } } catch (Exception) { throw; } }
private void btn_login_Click(object sender, System.EventArgs e) { if (string.IsNullOrWhiteSpace(txt_userName.Text.Trim()) || string.IsNullOrWhiteSpace(txt_password.Text.Trim())) { XtraMessageBox.Show("用户名或密码不能为空!"); return; } IUserService userService = new UserService(); var user = userService.CheckUser(txt_userName.Text.Trim(), txt_password.Text.Trim()); if (user == null || user.Id <= 0) { XtraMessageBox.Show("用户或密码不正确!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { InitUserInfo(user); this.Hide(); //业务日志 Log.Info(new LoggerInfo() { Message = $"{user.Name} 登录成功!", CreateUserId = user.Account, LogType = LogType.其他.ToString() }); var form = new Main(); form.ShowDialog(); } }
private void btn_save_Click(object sender, EventArgs e) { try { if (parentId <= 0) { XtraMessageBox.Show("请您先选择树形菜单!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } using (var db = SugarDao.GetInstance()) { if (string.IsNullOrWhiteSpace(txt_name.Text.Trim())) { XtraMessageBox.Show("请您输入名称!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var model = new BasicDictionary() { Id = id, ParentId = parentId, Name = txt_name.Text.Trim(), Character = txt_character.Text.Trim() }; if (Convert.ToBoolean(db.InsertOrUpdate(model))) { string msg = id > 0 ? $"【{parentName} 修改成功】 " : $"【{parentName} 新增成功】"; Log.Info(new LoggerInfo() { LogType = LogType.基础信息.ToString(), CreateUserId = UserInfo.Account, Message = msg + $" 名称:{Name},简写:{model.Character}" }); DialogResult = DialogResult.OK; this.Close(); } else { DialogResult = DialogResult.Cancel; } } } catch (Exception) { throw; } }
private void btn_save_Click(object sender, EventArgs e) { try { var entity = new Order() { Id = detailId, SupplierId = lue_gys.EditValue == null ? 0 : int.Parse(lue_gys.EditValue.ToString()), Status = 0, OrderNum = txt_OrderNum.Text.Trim(), CreateTime = detailId <= 0 ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : txt_CreateTime.Text.Trim(), CreateUserId = UserInfo.Account, Description = txt_Description.Text.Trim(), Type = 1, }; using (var db = SugarDao.GetInstance()) { var result = db.InsertOrUpdate(entity); if (Convert.ToBoolean(result)) { DialogResult = DialogResult.OK; var orderId = detailId > 0 ? detailId : int.Parse(result.ToString()); db.Update <OrderItem>(" OrderId= " + orderId, t => t.OrderNum == txt_OrderNum.Text.Trim() && t.OrderId <= 0); string msg = detailId > 0 ? $"【修改成功】" : $"【保存成功】"; Log.Info(new LoggerInfo() { LogType = LogType.采购入库.ToString(), CreateUserId = UserInfo.Account, Message = msg + $" 单号:{entity.OrderNum},供应商:{lue_gys.Text},描述:{entity.Description},创建日期:{entity.CreateTime},创建人:{entity.CreateUserId}", }); this.Close(); } else { DialogResult = DialogResult.Cancel; } } } catch (Exception) { throw; } }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { try { int id = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Id")); if (Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Status")) != 0) { XtraMessageBox.Show("已经提交的数据不能删除!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (id <= 0) { XtraMessageBox.Show("请您选择删除的数据!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (DialogResult.OK == XtraMessageBox.Show("您确定将该条记录删除吗?", "操作", MessageBoxButtons.OKCancel)) { using (var db = SugarDao.GetInstance()) { if (db.Update <Domain.Model.Order>("Status=-1", t => t.Id == id)) { Log.Info(new LoggerInfo() { LogType = LogType.采购入库.ToString(), CreateUserId = UserInfo.Account, Message = $"【删除成功】 Id:{id}", }); InitData(); } else { XtraMessageBox.Show("删除失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { XtraMessageBox.Show("删除异常!" + ex.Message); } }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { try { if (!btn_save.Visible) { XtraMessageBox.Show("对不起已经提交的单据,不能删除!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int id = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Id")); if (id <= 0) { XtraMessageBox.Show("请您选择删除的数据!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (var db = SugarDao.GetInstance()) { if (db.Delete <Domain.Model.OrderItem>(t => t.Id == id)) { Log.Info(new LoggerInfo() { LogType = LogType.入库明细.ToString(), CreateUserId = UserInfo.Account, Message = $"【删除成功】 Id:{id},单号:{txt_OrderNum.Text.Trim()}", }); InitGridView(); } else { XtraMessageBox.Show("删除失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { XtraMessageBox.Show("删除异常!" + ex.Message); } }
private void btn_delete_Click(object sender, EventArgs e) { try { int id = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Id")); if (id <= 0) { XtraMessageBox.Show("请您选择删除的数据!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (DialogResult.OK == XtraMessageBox.Show("您确定将该条记录删除吗?", "操作", MessageBoxButtons.OKCancel)) { using (var db = SugarDao.GetInstance()) { if (db.Delete <OrderItem>(t => t.Id == id)) { InitGridViewList(); CalcHJ(); var medicineName = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MedicineName").ToString(); Log.Info(new LoggerInfo() { LogType = LogType.出库明细.ToString(), CreateUserId = UserInfo.Account, Message = $"【删除成功】明细Id{id},单号:{_orderNum},药品名称:{medicineName}" }); } else { XtraMessageBox.Show("删除失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { XtraMessageBox.Show("删除异常!" + ex.Message); } }
private void btn_submit_Click(object sender, EventArgs e) { if (gridView1.RowCount <= 0) { XtraMessageBox.Show("单据明细列表不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var db = SugarDao.GetInstance(); try { var entity = new Order() { Id = detailId, SupplierId = lue_gys.EditValue == null ? 0 : int.Parse(lue_gys.EditValue.ToString()), Status = 1, OrderNum = txt_OrderNum.Text.Trim(), CreateTime = detailId <= 0 ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : txt_CreateTime.Text.Trim(), CreateUserId = UserInfo.Account, Description = txt_Description.Text.Trim(), Type = 1, }; db.CommandTimeOut = 30000; //设置超时时间 db.BeginTran(); //开启事务 var result = db.InsertOrUpdate(entity); if (Convert.ToBoolean(result)) { //根据单号更新明细列表id var orderId = detailId > 0 ? detailId : int.Parse(result.ToString()); db.Update <OrderItem>(" OrderId= " + orderId, t => t.OrderNum == txt_OrderNum.Text.Trim() && t.OrderId <= 0); if (InsertStockByOrderNum(db)) { db.CommitTran(); Log.Info(new LoggerInfo() { LogType = LogType.采购入库.ToString(), CreateUserId = UserInfo.Account, Message = $"【提交成功】 Id:{orderId},单号:{entity.OrderNum},供应商:{lue_gys.Text},描述:{entity.Description},创建日期:{entity.CreateTime},创建人:{entity.CreateUserId}", }); } else { db.RollbackTran(); XtraMessageBox.Show("提交失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } DialogResult = DialogResult.OK; this.Close(); } else { DialogResult = DialogResult.Cancel; } } catch (Exception ex) { db.RollbackTran(); XtraMessageBox.Show("提交失败!" + ex.Message, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_save_Click(object sender, EventArgs e) { try { if (_detailId < 0) { XtraMessageBox.Show("库存Id不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(txt_batchNum.Text.Trim())) { XtraMessageBox.Show("批号不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(txt_Amount.Text.Trim())) { XtraMessageBox.Show("数量不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (!txt_Amount.Text.Trim().IsNumber()) { XtraMessageBox.Show("数量必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (string.IsNullOrWhiteSpace(txt_cost.Text.Trim())) { XtraMessageBox.Show("进价不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (!txt_cost.Text.Trim().IsNumber()) { XtraMessageBox.Show("进价必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (string.IsNullOrWhiteSpace(txt_sale.Text.Trim())) { XtraMessageBox.Show("零售价不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (!txt_sale.Text.Trim().IsNumber()) { XtraMessageBox.Show("零售价必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } using (var db = SugarDao.GetInstance()) { var result = db.Update <Stock>( $" BatchNum='{txt_batchNum.Text.Trim()}',Amount={txt_Amount.Text.Trim()},Cost={txt_cost.Text.Trim()},Sale={txt_sale.Text.Trim()},BeginDate='{(string.IsNullOrWhiteSpace(txt_beginDate.Text.Trim()) ? null : DateTime.Parse(txt_beginDate.Text.Trim()).ToString("yyyy-MM-dd"))}',EndDate='{(string.IsNullOrWhiteSpace(txt_endDate.Text.Trim()) ? null : DateTime.Parse(txt_endDate.Text.Trim()).ToString("yyyy-MM-dd"))}',UpdateUserId='{UserInfo.Account}',UpdateTime='{DateTime.Now:yyyy-MM-dd}'", t => t.Id == _detailId); if (result) { Log.Info(new LoggerInfo() { LogType = LogType.库存修改.ToString(), CreateUserId = UserInfo.Account, Message = $"【修改成功】 库存id:{_detailId},药品名称:{txt_name.Text.Trim()},批号:{txt_batchNum.Text.Trim()},库存数量:{txt_Amount.Text.Trim()},进价:{txt_cost.Text.Trim()},零售价:{txt_sale.Text.Trim()},生产日期:{txt_beginDate.Text.Trim()},到期日期:{txt_endDate.Text.Trim()}" }); DialogResult = DialogResult.OK; this.Close(); } else { DialogResult = DialogResult.Cancel; } } } catch (Exception) { throw; } }
private void btn_save_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(_orderNum)) { XtraMessageBox.Show("单号不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(txt_batchNum.Text.Trim())) { XtraMessageBox.Show("批号不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(txt_Amount.Text.Trim())) { XtraMessageBox.Show("数量不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (!txt_Amount.Text.Trim().IsNumber()) { XtraMessageBox.Show("数量必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (string.IsNullOrWhiteSpace(txt_cost.Text.Trim())) { XtraMessageBox.Show("进价不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (!txt_cost.Text.Trim().IsNumber()) { XtraMessageBox.Show("进价必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (string.IsNullOrWhiteSpace(txt_sale.Text.Trim())) { XtraMessageBox.Show("零售价不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (!txt_sale.Text.Trim().IsNumber()) { XtraMessageBox.Show("零售价必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } var entity = new OrderItem() { Id = _detailId, MedicineId = int.Parse(lue_name.EditValue.ToString()), OrderNum = _orderNum, Amount = decimal.Parse(txt_Amount.Text.Trim()), Cost = decimal.Parse(txt_cost.Text.Trim()), Sale = decimal.Parse(txt_sale.Text.Trim()), BatchNum = txt_batchNum.Text.Trim(), BeginDate = string.IsNullOrWhiteSpace(txt_beginDate.Text.Trim()) ? null : DateTime.Parse(txt_beginDate.Text.Trim()).ToString("yyyy-MM-dd"), EndDate = string.IsNullOrWhiteSpace(txt_endDate.Text.Trim()) ? null : DateTime.Parse(txt_endDate.Text.Trim()).ToString("yyyy-MM-dd"), }; using (var db = SugarDao.GetInstance()) { var result = db.InsertOrUpdate(entity); if (Convert.ToBoolean(result)) { string msg = _detailId > 0 ? $"【修改成功】 " : $"【新增成功】"; var medicine = db.Queryable <Domain.Model.Medicine>().SingleOrDefault(t => t.Id == entity.MedicineId); Log.Info(new LoggerInfo() { LogType = LogType.入库明细.ToString(), CreateUserId = UserInfo.Account, Message = msg + $"单号:{entity.OrderNum},Id:{entity.Id},药品名称:{medicine?.Name},数量:{entity.Amount},进价:{entity.Cost},零售价:{entity.Sale},批号:{entity.BatchNum},生产日期:{entity.BeginDate},到期日期:{entity.EndDate}" }); DialogResult = DialogResult.OK; this.Close(); } else { DialogResult = DialogResult.Cancel; } } } catch (Exception) { throw; } }
private void btn_Submit_Click(object sender, EventArgs e) { if (gridView1.RowCount <= 0) { XtraMessageBox.Show("明细列表不能空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } var db = SugarDao.GetInstance(); try { db.CommandTimeOut = 30000; //设置超时时间 db.BeginTran(); //开启事务 var entity = new Order() { Id = _detailId, Status = 1, OrderNum = _orderNum, CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), CreateUserId = UserInfo.Account, Type = 2, }; var result = db.InsertOrUpdate(entity); if (Convert.ToBoolean(result)) { var orderId = _detailId > 0 ? _detailId : int.Parse(result.ToString()); db.Update <OrderItem>(" OrderId= " + orderId, t => t.OrderNum == _orderNum && t.OrderId <= 0); var errorMsg = CalcStockByOrderNum(db); if (string.IsNullOrWhiteSpace(errorMsg)) { db.CommitTran(); Log.Info(new LoggerInfo() { LogType = LogType.销售出库.ToString(), CreateUserId = UserInfo.Account, Message = $"【结账成功】单号:{_orderNum},单据Id:{orderId},描述:{entity.Description},合计:{txt_hj.Text.Trim()},创建日期:{entity.CreateTime},创建人:{entity.CreateUserId}", }); DialogResult = DialogResult.OK; this.Close(); } else { db.RollbackTran(); XtraMessageBox.Show(errorMsg, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { DialogResult = DialogResult.Cancel; } } catch (Exception ex) { db.RollbackTran(); XtraMessageBox.Show("结账异常!" + ex.Message, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); ; } }
private void btn_add_Click(object sender, EventArgs e) { if (gridView2.RowCount <= 0) { XtraMessageBox.Show("不能大于库存数量!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrWhiteSpace(txt_dj.Text.Trim())) { XtraMessageBox.Show("单价不能为空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!txt_dj.Text.Trim().IsNumber()) { XtraMessageBox.Show("单价必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrWhiteSpace(txt_sl.Text.Trim())) { XtraMessageBox.Show("数量不能空!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!txt_sl.Text.Trim().IsNumber()) { XtraMessageBox.Show("单价必须为数字!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int stockId = int.Parse(gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "Id").ToString()); //库存Id using (var db = SugarDao.GetInstance()) { var entity = db.Queryable <Stock>().SingleOrDefault(t => t.Id == stockId); if (entity != null && entity.Id > 0) { var currCount = int.Parse(txt_sl.Text.Trim()); //录入数量 if (entity.Amount < currCount) { XtraMessageBox.Show("当前数量不能大于库存数量!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var item = new OrderItem() { OrderNum = _orderNum, BatchNum = entity.BatchNum, Cost = entity.Cost, Sale = decimal.Parse(txt_dj.Text.Trim()), Amount = decimal.Parse(txt_sl.Text.Trim()), MedicineId = entity.MedicineId, BeginDate = entity.BeginDate, EndDate = entity.EndDate, StockId = stockId, }; //检查是否已经添加 var IsExist = db.Queryable <OrderItem>()?.SingleOrDefault(t => t.OrderNum == _orderNum && t.MedicineId == item.MedicineId && t.BatchNum == item.BatchNum); if (IsExist != null && IsExist.Id > 0) { DialogResult dr = XtraMessageBox.Show("该批次药品已经添加,您确认重复添加吗?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.Cancel) { return; } } if (!Convert.ToBoolean(db.InsertOrUpdate(item))) { XtraMessageBox.Show("添加失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { InitGridViewList(); CalcHJ(); var medicine = db.Queryable <Domain.Model.Medicine>().SingleOrDefault(t => t.Id == entity.MedicineId); Log.Info(new LoggerInfo() { LogType = LogType.出库明细.ToString(), CreateUserId = UserInfo.Account, Message = $"【新增成功】单号:{item.OrderNum},库存Id:{entity.Id},药品名称:{medicine?.Name},批号:{entity.BatchNum},数量:{item.Amount},进价:{entity.Cost},零售价:{item.Sale}" }); } } else { XtraMessageBox.Show("未查到该库存!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }