private void toolEdit_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (DBGrid.CurrentRow == null) { return; } modWarehouseProductTransfer mod = (modWarehouseProductTransfer)DBGrid.CurrentRow.DataBoundItem; EditWarehouseProductTransfer frm = new EditWarehouseProductTransfer(); frm.EditItem(mod.Id); if (frm.ShowDialog() == DialogResult.OK) { LoadData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }
public void EditItem(int id) { try { this.Cursor = Cursors.WaitCursor; _action = "EDIT"; modWarehouseProductTransfer mod = _dal.GetItem(id, out Util.emsg); if (mod != null) { txtId.Text = id.ToString(); dtpTransferDate.Value = mod.TransferDate; txtNo.Text = mod.InvNo; txtProductId.Text = mod.ProductId; txtProductName.Text = mod.ProductName; txtSize.Text = mod.Size.ToString(); txtQty.Text = mod.Qty.ToString(); txtWarehouseFrom.Text = mod.WarehouseFrom.ToString(); txtWarehouseTo.Text = mod.WarehouseTo.ToString(); txtRemark.Text = mod.Remark; if (mod.Status == 1) { status4.Image = Properties.Resources.audited; Util.ChangeStatus(this, true); toolSave.Enabled = false; } else { status4.Image = null; toolSave.Visible = true; Util.ChangeStatus(this, false); txtId.ReadOnly = true; toolSave.Enabled = true; } dalProductList dalpdt = new dalProductList(); modProductList modpdt = dalpdt.GetItem(mod.ProductId, out Util.emsg); if (modpdt.SizeFlag == 1) { txtSize.Enabled = true; } else { txtSize.Enabled = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }
/// <summary> /// audit warehouse inout /// <summary> /// <param name=id>id</param> /// <param name=updateuser>updateuser</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Audit(int id, string updateuser, out string emsg) { string sql = string.Empty; SqlConnection conn = SqlHelper.getConn(); conn.Open(); SqlTransaction trans = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); try { modWarehouseProductTransfer mod = GetItem(id, out emsg); if (mod.Status == 1) { emsg = "这张单据已经审核,您无须再审"; return(false); } sql = string.Format("insert into warehouse_product_inout(warehouse_id,product_id,size,form_id,form_type,inv_no,inout_date,start_qty,input_qty,output_qty,remark,update_user,update_time)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',getdate())", mod.WarehouseFrom, mod.ProductId, mod.Size, id, "转仓出库", mod.InvNo, mod.TransferDate, 0, 0, mod.Qty, mod.Remark, updateuser); SqlHelper.PrepareCommand(cmd, conn, trans, CommandType.Text, sql, null); cmd.ExecuteNonQuery(); sql = string.Format("insert into warehouse_product_inout(warehouse_id,product_id,size,form_id,form_type,inv_no,inout_date,start_qty,input_qty,output_qty,remark,update_user,update_time)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',getdate())", mod.WarehouseTo, mod.ProductId, mod.Size, id, "转仓入库", mod.InvNo, mod.TransferDate, 0, mod.Qty, 0, mod.Remark, updateuser); SqlHelper.PrepareCommand(cmd, conn, trans, CommandType.Text, sql, null); cmd.ExecuteNonQuery(); sql = string.Format("update warehouse_product_transfer set status={0},audit_man='{1}',audit_time=getdate() where id='{2}'", 1, updateuser, id); SqlHelper.PrepareCommand(cmd, conn, trans, CommandType.Text, sql, null); cmd.ExecuteNonQuery(); trans.Commit(); emsg = string.Empty; return(true); } catch (Exception ex) { trans.Rollback(); emsg = dalUtility.ErrorMessage(ex.Message); return(false); } finally { trans.Dispose(); cmd.Dispose(); if (conn.State != ConnectionState.Closed) { conn.Dispose(); } } }
/// <summary> /// reset warehouse inout /// <summary> /// <param name=id>id</param> /// <param name=updateuser>updateuser</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Reset(int id, string updateuser, out string emsg) { string sql = string.Empty; SqlConnection conn = SqlHelper.getConn(); conn.Open(); SqlTransaction trans = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); try { modWarehouseProductTransfer mod = GetItem(id, out emsg); if (mod.Status == 0) { emsg = "这张单据尚未审核,您无须重置"; return(false); } sql = string.Format("delete warehouse_product_inout where form_id='{0}' and (form_type='{1}' or form_type='{2}')", id, "转仓出库", "转仓入库"); SqlHelper.PrepareCommand(cmd, conn, trans, CommandType.Text, sql, null); cmd.ExecuteNonQuery(); sql = string.Format("update warehouse_product_transfer set status={0},audit_man='{1}',audit_time=null where id='{2}'", 0, updateuser, id); SqlHelper.PrepareCommand(cmd, conn, trans, CommandType.Text, sql, null); cmd.ExecuteNonQuery(); trans.Commit(); emsg = string.Empty; return(true); } catch (Exception ex) { trans.Rollback(); emsg = dalUtility.ErrorMessage(ex.Message); return(false); } finally { trans.Dispose(); cmd.Dispose(); if (conn.State != ConnectionState.Closed) { conn.Dispose(); } } }
/// <summary> /// get table record /// <summary> /// <param name=id>id</param> /// <param name=out emsg>return error message</param> ///<returns>get a record detail of warehouseproducttransfer</returns> public modWarehouseProductTransfer GetItem(int id, out string emsg) { try { //Execute a query to read the categories string sql = string.Format("select a.id,a.warehouse_from,a.warehouse_to,a.status,a.inv_no,a.transfer_date,a.product_id,b.product_name,a.size,a.qty,a.remark,a.update_user,a.update_time " + "from warehouse_product_transfer a,product_list b where a.product_id=b.product_id and a.id={0} order by a.id", id); using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { if (rdr.Read()) { modWarehouseProductTransfer model = new modWarehouseProductTransfer(); model.Id = Convert.ToInt32(rdr["id"]); model.WarehouseFrom = Convert.ToString(rdr["warehouse_from"]); model.WarehouseTo = Convert.ToString(rdr["warehouse_to"]); model.Status = Convert.ToInt32(rdr["status"]); model.InvNo = Convert.ToString(rdr["inv_no"]); model.TransferDate = Convert.ToDateTime(rdr["transfer_date"]); model.ProductId = Convert.ToString(rdr["product_id"]); model.ProductName = Convert.ToString(rdr["product_name"]); model.Size = Convert.ToDecimal(rdr["size"]); model.Qty = Convert.ToDecimal(rdr["qty"]); model.Remark = Convert.ToString(rdr["remark"]); model.UpdateUser = Convert.ToString(rdr["update_user"]); model.UpdateTime = Convert.ToDateTime(rdr["update_time"]); emsg = null; return(model); } else { emsg = "Error on read data"; return(null); } } } catch (Exception ex) { emsg = ex.Message; return(null); } }
private void toolDel_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (DBGrid.CurrentRow == null) { return; } if (MessageBox.Show(clsTranslate.TranslateString("Do you really want to delete it?"), clsTranslate.TranslateString("Confirm"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } modWarehouseProductTransfer mod = _dal.GetItem(Convert.ToInt32(DBGrid.CurrentRow.Cells[0].Value), out Util.emsg); if (mod.Status == 1) { MessageBox.Show("该单据已审核,您不能删除!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool ret = _dal.Delete(mod.Id, out Util.emsg); if (ret) { LoadData(); } else { MessageBox.Show(Util.emsg, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }
/// <summary> /// get all warehouseproducttransfer /// <summary> /// <param name=getwhere>getwhere</param> /// <param name=out emsg>return error message</param> ///<returns>details of all warehouseproducttransfer</returns> public BindingCollection <modWarehouseProductTransfer> GetIList(string getwhere, out string emsg) { try { BindingCollection <modWarehouseProductTransfer> modellist = new BindingCollection <modWarehouseProductTransfer>(); //Execute a query to read the categories string sql = "select a.id,a.warehouse_from,a.warehouse_to,a.status,a.inv_no,a.transfer_date,a.product_id,b.product_name,a.size,a.qty,a.remark,a.update_user,a.update_time " + "from warehouse_product_transfer a,product_list b where a.product_id=b.product_id " + getwhere + " order by a.id"; using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql)) { while (rdr.Read()) { modWarehouseProductTransfer model = new modWarehouseProductTransfer(); model.Id = Convert.ToInt32(rdr["id"]); model.WarehouseFrom = Convert.ToString(rdr["warehouse_from"]); model.WarehouseTo = Convert.ToString(rdr["warehouse_to"]); model.Status = Convert.ToInt32(rdr["status"]); model.InvNo = Convert.ToString(rdr["inv_no"]); model.TransferDate = Convert.ToDateTime(rdr["transfer_date"]); model.ProductId = Convert.ToString(rdr["product_id"]); model.ProductName = Convert.ToString(rdr["product_name"]); model.Size = Convert.ToDecimal(rdr["size"]); model.Qty = Convert.ToDecimal(rdr["qty"]); model.Remark = Convert.ToString(rdr["remark"]); model.UpdateUser = Convert.ToString(rdr["update_user"]); model.UpdateTime = Convert.ToDateTime(rdr["update_time"]); modellist.Add(model); } } emsg = null; return(modellist); } catch (Exception ex) { emsg = ex.Message; return(null); } }
/// <summary> /// update a warehouseproducttransfer /// <summary> /// <param name=id>id</param> /// <param name=mod>model object of warehouseproducttransfer</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Update(int id, modWarehouseProductTransfer mod, out string emsg) { try { string sql = string.Format("update warehouse_product_transfer set warehouse_from='{0}',warehouse_to='{1}',status='{2}',inv_no='{3}',transfer_date='{4}',product_id='{5}',size='{6}',qty='{7}',remark='{8}',update_user='******',update_time=getdate() where id={10}", mod.WarehouseFrom, mod.WarehouseTo, mod.Status, mod.InvNo, mod.TransferDate, mod.ProductId, mod.Size, mod.Qty, mod.Remark, mod.UpdateUser, id); int i = SqlHelper.ExecuteNonQuery(sql); if (i > 0) { emsg = null; return(true); } else { emsg = "Unknown error when ExecuteNonQuery!"; return(false); } } catch (Exception ex) { emsg = ex.Message; return(false); } }
/// <summary> /// insert a warehouseproducttransfer /// <summary> /// <param name=mod>model object of warehouseproducttransfer</param> /// <param name=out emsg>return error message</param> /// <returns>true/false</returns> public bool Insert(modWarehouseProductTransfer mod, out string emsg) { try { string sql = string.Format("insert into warehouse_product_transfer(warehouse_from,warehouse_to,status,inv_no,transfer_date,product_id,size,qty,remark,update_user,update_time)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',getdate())", mod.WarehouseFrom, mod.WarehouseTo, mod.Status, mod.InvNo, mod.TransferDate, mod.ProductId, mod.Size, mod.Qty, mod.Remark, mod.UpdateUser); int i = SqlHelper.ExecuteNonQuery(sql); if (i > 0) { emsg = null; return(true); } else { emsg = "Unknown error when ExecuteNonQuery!"; return(false); } } catch (Exception ex) { emsg = ex.Message; return(false); } }
private void toolSave_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (dtpTransferDate.Value < Util.modperiod.StartDate) { MessageBox.Show("该日期的数据已锁定,不能更新数据!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); dtpTransferDate.Focus(); return; } if (string.IsNullOrEmpty(txtSize.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Size") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSize.Focus(); return; } else if (!Util.IsNumeric(txtSize.Text)) { MessageBox.Show(clsTranslate.TranslateString("Size") + clsTranslate.TranslateString(" must be a numeric!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSize.Focus(); return; } else if (Convert.ToDecimal(txtSize.Text.Trim()) <= 0) { MessageBox.Show(clsTranslate.TranslateString("Size") + clsTranslate.TranslateString(" must > 0!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSize.Focus(); return; } if (string.IsNullOrEmpty(txtQty.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Qty") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtQty.Focus(); return; } else if (!Util.IsNumeric(txtQty.Text)) { MessageBox.Show(clsTranslate.TranslateString("Qty") + clsTranslate.TranslateString(" must be a numeric!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtQty.Focus(); return; } else if (Convert.ToDecimal(txtQty.Text.Trim()) <= 0) { MessageBox.Show(clsTranslate.TranslateString("Qty") + clsTranslate.TranslateString(" must > 0!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtQty.Focus(); return; } if (string.IsNullOrEmpty(txtProductId.Text)) { MessageBox.Show(clsTranslate.TranslateString("Product Id") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProductId.Focus(); return; } if (string.IsNullOrEmpty(txtProductId.Text)) { MessageBox.Show(clsTranslate.TranslateString("Product Id") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProductId.Focus(); return; } if (string.IsNullOrEmpty(txtWarehouseFrom.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Warehouse from") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtWarehouseFrom.Focus(); return; } if (string.IsNullOrEmpty(txtWarehouseTo.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Warehouse to") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtWarehouseTo.Focus(); return; } if (txtWarehouseFrom.Text.Trim() == txtWarehouseTo.Text.Trim()) { MessageBox.Show(clsTranslate.TranslateString("出库与入仓不能相同"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtWarehouseTo.Focus(); return; } if (clsLxms.GetParameterValue("NEED_INOUT_NO").CompareTo("T") == 0 && string.IsNullOrEmpty(txtNo.Text)) { MessageBox.Show(clsTranslate.TranslateString("No") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtNo.Focus(); return; } modWarehouseProductTransfer mod = new modWarehouseProductTransfer(); mod.Id = Convert.ToInt32(txtId.Text); mod.TransferDate = dtpTransferDate.Value; mod.InvNo = txtNo.Text.Trim(); mod.ProductId = txtProductId.Text.Trim(); mod.ProductName = txtProductName.Text.Trim(); if (clsLxms.GetProductSizeFlag(mod.ProductId) == 0) { mod.Size = 1; } else { mod.Size = Convert.ToDecimal(txtSize.Text); } mod.Qty = Convert.ToDecimal(txtQty.Text); mod.WarehouseFrom = txtWarehouseFrom.Text.Trim(); mod.WarehouseTo = txtWarehouseTo.Text.Trim(); mod.Remark = txtRemark.Text.Trim(); mod.UpdateUser = Util.UserId; mod.Status = 0; bool ret; if (_action == "ADD" || _action == "NEW") { ret = _dal.Insert(mod, out Util.emsg); } else { ret = _dal.Update(mod.Id, mod, out Util.emsg); } if (ret) { this.DialogResult = DialogResult.OK; this.Dispose(); } else { MessageBox.Show(Util.emsg, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }
private void toolAudit_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (DBGrid.RowCount == 0) { return; } if (DBGrid.SelectedRows.Count == 0 && DBGrid.CurrentRow == null) { return; } if (MessageBox.Show(clsTranslate.TranslateString("Do you really want to audit it?"), clsTranslate.TranslateString("Confirm"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } if (DBGrid.SelectedRows.Count == 0) { modWarehouseProductTransfer mod = _dal.GetItem(Convert.ToInt32(DBGrid.CurrentRow.Cells[0].Value), out Util.emsg); if (_dal.Audit(mod.Id, Util.UserId, out Util.emsg)) { MessageBox.Show(clsTranslate.TranslateString("Audit Success!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(); } else { MessageBox.Show(clsTranslate.TranslateString(Util.emsg), mod.Id.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } else { for (int i = DBGrid.SelectedRows.Count - 1; i >= 0; i--) { modWarehouseProductTransfer mod = _dal.GetItem(Convert.ToInt32(DBGrid.SelectedRows[i].Cells[0].Value), out Util.emsg); if (_dal.Audit(mod.Id, Util.UserId, out Util.emsg)) { DBGrid.SelectedRows[i].Cells["status"].Value = 1; DBGrid.SelectedRows[i].DefaultCellStyle.ForeColor = Color.DarkGray; DBGrid.SelectedRows[i].Selected = false; } else { MessageBox.Show(clsTranslate.TranslateString(Util.emsg), mod.Id.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } LoadData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }