private void button2_Click(object sender, EventArgs e) { if (text单位.Text == "") { MessageBox.Show("未填写单位"); return; } if (text供应单价.Text == "") { MessageBox.Show("未填写供应单价"); return; } if (com供应商.Text == "") { MessageBox.Show("未填写供应商"); return; } try { MaterialDAO at = new MaterialDAO(); MaterialFlow mtf = new MaterialFlow(); //mtf.Id = com原料编号 mtf.Type = "入仓"; mtf.FlowCount = Convert.ToInt32(textBox进出数量.Text); mtf.MaterialId = Convert.ToInt32(com原料编号.SelectedValue); mtf.Supplier = com供应商.Text; mtf.Price = Convert.ToDouble(text供应单价.Text); mtf.Operator = Utils.GetCurrentUsername(); mtf.OccurredTime = DateTime.Now; String name = textBoxNewName.Text;//原料名称 DialogResult dr = MessageBox.Show("将要对原料[" + name + "]进行入仓,供应商:" + mtf.Supplier + ", 单价: " + mtf.Price + ", 数量:" + mtf.FlowCount, "请确认", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { //原料名称this.material.GetMaterialNameBySerial(com原料编号.Text); if (material.AddNewMaterialEx(mtf, name, text单位.Text)) { MessageBox.Show("[" + name + "]更新库存成功!"); dataGridView1.DataSource = this.material.GetAllMaterials(); dataGridView1.Update(); dataGridView2.DataSource = this.material.GetAllMaterialFlow(); dataGridView2.Update(); } } } catch (Exception ex) { MessageBox.Show("更新库存失败!" + ex.ToString()); } }
public bool DelMaterialFlow(MaterialFlow material) { try { string sql = "DELETE FROM qiaotai.原材料进出仓 WHERE 库存数量='" + material.FlowCount + "' AND 原料编号='" + material.MaterialId + "';"; MySqlCommand cmd = new MySqlCommand(sql, this.Connection); this.Connection.Open(); cmd.ExecuteNonQuery(); this.Connection.Close(); return(true); } catch (Exception ex) { this.Connection.Close(); throw ex; } }
//public bool AddNewMaterial(Material material)//增加进仓原料 //{ // //增加仓库原料,先判断是否存在此种原料,如存在看单位是否一致,名称是否一致,一致则增加库存,否则报错。如没有这种原料则新增一行 // try // { // //判断存在 // string sql = "SELECT * FROM qiaotai.原材料 WHERE 原料名称='" + material.Name +"' AND 单位='"+material.Unit+"';"; // MySqlCommand cmd = new MySqlCommand(sql, this.Connection); // MySqlDataAdapter ap = new MySqlDataAdapter(cmd); // DataTable dt = new DataTable(); // this.Connection.Open(); // ap.Fill(dt); // this.Connection.Close(); // if (dt.Rows.Count != 0) // { // //存在此种原材料,增加库存 // sql = "UPDATE qiaotai.原材料 SET 库存数量='" +Convert.ToString(material.StockCount +Convert.ToUInt16(dt.Rows[0][3].ToString())) +"' WHERE 原料名称='" + material.Name + "' AND 单位='" + material.Unit + "';"; // MySqlCommand cmd1 = new MySqlCommand(sql, this.Connection); // this.Connection.Open(); // cmd1.ExecuteNonQuery(); // this.Connection.Close(); // return true; // } // else // { // //不存在此种原材料,增加新材料 // } // } // catch (Exception ex) { return false; } //} public bool AddNewMaterialFlow(MaterialFlow material, String mtName, String mtUnit) { try { string sql = "INSERT INTO qiaotai.原材料进出仓(类型,数量,原料编号,供应商,供应单价,发生时间,操作员) VALUES ('" + material.Type + "','" + material.FlowCount + "','" + material.MaterialId + "','" + material.Supplier + "','" + material.Price + "','" + material.OccurredTime.ToString("yyyy/MM/dd HH:mm:ss") + "','" + material.Operator + "');"; MySqlCommand cmd = new MySqlCommand(sql, this.Connection); this.Connection.Open(); cmd.ExecuteNonQuery(); this.Connection.Close(); return(true); } catch (Exception ex) { this.Connection.Close(); throw ex; } }
public DataTable GetAllMaterialFlow() { try { MaterialFlow material = new MaterialFlow(); string sql = "SELECT * FROM qiaotai.原材料进出仓 ORDER BY 编号 DESC;"; MySqlCommand cmd = new MySqlCommand(sql, this.Connection); MySqlDataAdapter ap = new MySqlDataAdapter(cmd); DataTable dt = new DataTable(); this.Connection.Open(); ap.Fill(dt); this.Connection.Close(); return(dt); } catch (Exception ex) { this.Connection.Close(); throw ex; } }
/// <summary> /// Calculates the total transport performance /// (expected material flow multiplied with the distances) /// </summary> public void CalculateFitness() { Fitness = 0.0; //to be determined int locU, locV; //locations //iterate all pairs of units for (int u = 0; u < MaterialFlow.GetLength(0); u++) { locU = AssignmentSolution[u]; for (int v = 0; v < MaterialFlow.GetLength(1); v++) { locV = AssignmentSolution[v]; Fitness += MaterialFlow[u, v] * Distances[locU, locV]; } } }
public bool AddNewMaterialEx(MaterialFlow material, String mtName, String mtUnit) { try { Material mt = new Material(); mt.Id = material.MaterialId; mt.Unit = mtUnit; mt.StockCount = material.FlowCount; if (mt.Id == -1) { mt.Name = mtName; material.MaterialId = mt.Id = this.dao.AddNewMaterial(mt); } else { this.dao.UpdateMaterial(mt); } return(this.dao.AddNewMaterialFlow(material, mtName, mtUnit)); } catch (Exception ex) { throw ex; } }
private void button1_Click(object sender, EventArgs e) { string str = "已完成原料编号领料:"; //for (int i = 0; i < dataGridView1.RowCount - 1; i++) //{ // if (dataGridView1.Rows[i].Cells["供应商"].Value.ToString() == "") // { // MessageBox.Show("请选择供应商和单价!"); // return; // } //} try { for (int i = 0; i < dataGridView1.RowCount; i++) { if (Convert.ToInt32(dataGridView1.Rows[i].Cells["需要原料数量"].Value) >= Convert.ToInt32(dataGridView1.Rows[i].Cells["库存数量"].Value)) { MessageBox.Show("领料失败:\n\r原料库存不足!"); return; } } bool ok = true; int num = 0; for (int i = 0; i < dataGridView1.RowCount; i++) { num = Convert.ToInt32(dataGridView1.Rows[i].Cells["库存数量"].Value) - Convert.ToInt32(dataGridView1.Rows[i].Cells["需要原料数量"].Value); if (mtm.MaterialDesTo(dataGridView1.Rows[i].Cells["原料编号"].Value.ToString(), num) == true) { str += dataGridView1.Rows[i].Cells["原料编号"].Value.ToString() + ","; //ok = false; //***************************** MaterialDAO at = new MaterialDAO(); MaterialFlow mtf = new MaterialFlow(); //mtf.Id = com原料编号 mtf.Type = "领料生产"; mtf.FlowCount = 0 - Convert.ToInt32(dataGridView1.Rows[i].Cells["需要原料数量"].Value); mtf.MaterialId = Convert.ToInt32(dataGridView1.Rows[i].Cells["原料编号"].Value); //供应商选择 //mtf.Supplier = dataGridView1.Rows[i].Cells["供应商"].Value.ToString(); //mtf.Price = Convert.ToDouble(dataGridView1.Rows[i].Cells["供应单价"].Value); //mtf.Price = 0.0; mtf.Operator = Utils.GetCurrentUsername(); mtf.OccurredTime = DateTime.Now; String name = text原料名称.Text;//原料名称 if (material.AddNewMaterialEx(mtf, name, text单位.Text)) { com供应商.Text = ""; // text单价.Text = ""; // text单位.Text = ""; text原料名称.Text = ""; } //***************************** } else { ok = false; MessageBox.Show("领料失败!此原料为," + dataGridView1.Rows[i].Cells["原料编号"].Value.ToString()); return; } } if (ok) { if (ppm.UpdatePlanStatus(ProductionPlanStatus.PROCESSING, textBox订单.Text)) { MessageBox.Show("领料成功!!!"); this.Close(); } else { MessageBox.Show("领料失败!"); } } } catch (Exception ex) { MessageBox.Show("领料失败!"); }; }