/// <summary> /// 向上移动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BT_Down_Click(object sender, EventArgs e) { if (this.DGV_Plan.CurrentRow == null) { MessageBox.Show("请选择要需要操作的步序所在行"); } else { int row = DGV_Plan.SelectedRows[0].Index; if (row <= 0) { MessageBox.Show("此步序已在顶端,不能再上移!"); } else { AsmPlanObject apo = AsmPlan_BLL.GetPlanObjectByCondition(" WHERE ID=" + Convert.ToInt32(planDt.Rows[row]["ID"].ToString())); apo.PLAN_LEVEL = apo.PLAN_LEVEL - 1; AsmPlanObject apo_1 = AsmPlan_BLL.GetPlanObjectByCondition("WHERE ID=" + Convert.ToInt32(planDt.Rows[row - 1]["ID"].ToString())); apo_1.PLAN_LEVEL = apo_1.PLAN_LEVEL + 1; if (AsmPlan_BLL.UpdatePlan(apo) > 0 && AsmPlan_BLL.UpdatePlan(apo_1) > 0) { ReflshDataGridView(); DGV_Plan.ClearSelection(); DGV_Plan.Rows[row - 1].Selected = true; } else { MessageBox.Show("上移失败!"); } } } }
public static AsmPlanObject GetPlanObjectByCondition(string sql) { AsmPlanObject apo = null; string sl = "SELECT ID,DT,NAME,PRODUCTION_ID,NUMBER,COMPLETE_NUMBER,REMAIND_NUMBER,OK_NUMBER,NG_NUMBER,LINE_ID,PLAN_LEVEL,COMPLETE_FLAG,OPREATION_USER,CREATE_BARCODE_FLAG FROM dbo.R_PMS_PLAN_T " + sql; DataTable dt = new DataTable(); dt = ClsCommon.dbSql.ExecuteDataTable(sl); if (dt.Rows.Count > 0) { apo = new AsmPlanObject(); apo.ID = Convert.ToInt32(dt.Rows[0]["ID"].ToString()); apo.DT = Convert.ToDateTime(dt.Rows[0]["DT"].ToString()); apo.PRODUCTION_ID = Convert.ToInt32(dt.Rows[0]["PRODUCTION_ID"].ToString()); apo.NAME = dt.Rows[0]["NAME"].ToString(); apo.NUMBER = Convert.ToInt32(dt.Rows[0]["NUMBER"].ToString()); apo.COMPLETE_NUMBER = Convert.ToInt32(dt.Rows[0]["COMPLETE_NUMBER"].ToString()); apo.REMAIND_NUMBER = Convert.ToInt32(dt.Rows[0]["REMAIND_NUMBER"].ToString()); apo.OK_NUMBER = Convert.ToInt32(dt.Rows[0]["OK_NUMBER"].ToString()); apo.NG_NUMBER = Convert.ToInt32(dt.Rows[0]["NG_NUMBER"].ToString()); apo.LINE_ID = Convert.ToInt32(dt.Rows[0]["LINE_ID"].ToString()); apo.PLAN_LEVEL = Convert.ToInt32(dt.Rows[0]["PLAN_LEVEL"].ToString()); apo.COMPLETE_FLAG = dt.Rows[0]["COMPLETE_FLAG"].ToString(); apo.OPREATION_USER = dt.Rows[0]["OPREATION_USER"].ToString(); apo.CREATE_BARCODE_FLAG = dt.Rows[0]["CREATE_BARCODE_FLAG"].ToString(); } return(apo); }
/// <summary> /// 新增用户 /// </summary> /// <param name="aak"></param> /// <returns></returns> public static int AddPlan(AsmPlanObject uo) { using (IDbConnection conn = ClsCommon.OpenConnection()) //这里访问的是Sqlite数据文件,这里OpenConnection即上边获取连接数据库对象方法 { var result = conn.Insert(uo); return(Convert.ToInt32(result)); } }
/// <summary> /// 更新单个用户 /// </summary> /// <param name="uo"></param> /// <returns></returns> public static int UpdatePlan(AsmPlanObject uo) { var result = 0; using (IDbConnection conn = ClsCommon.OpenConnection()) //这里访问的是Sqlite数据文件,这里OpenConnection即上边获取连接数据库对象方法 { result = conn.Update(uo); } return(Convert.ToInt32(result)); }
private void BT_Save_Click(object sender, EventArgs e) { DataTable dtX = AsmPlan_BLL.GetPlanByName(TB_PlanNumber.Text.ToString().Trim()); if (!(dtX.Rows.Count > 0)) { if (!String.IsNullOrEmpty(CB_Line.SelectedItem.ToString()) && !String.IsNullOrEmpty(TB_PlanNumber.Text) && !String.IsNullOrEmpty(CB_ProductionType.SelectedItem.ToString()) && !String.IsNullOrEmpty(UD_ProductionNumber.Value.ToString()) && !String.IsNullOrEmpty(TB_OperationUser.Text)) { AsmPlanObject apo = new AsmPlanObject(); apo.LINE_ID = Convert.ToInt32(CB_Line.SelectedValue); apo.DT = DateTime.Now; apo.NAME = TB_PlanNumber.Text; apo.PRODUCTION_ID = Convert.ToInt32(CB_ProductionType.SelectedValue); apo.NUMBER = Convert.ToInt32(UD_ProductionNumber.Value); apo.OPREATION_USER = TB_OperationUser.Text; apo.COMPLETE_FLAG = "0";//表示初始化 apo.CREATE_BARCODE_FLAG = "0"; DataTable dt = AsmPlan_BLL.GetMaxLevelPlanByCondition(); if (dt.Rows.Count > 0 && !String.IsNullOrEmpty(dt.Rows[0]["LEVEL"].ToString())) { apo.PLAN_LEVEL = Convert.ToInt32(dt.Rows[0]["LEVEL"].ToString()) + 1; } else { apo.PLAN_LEVEL = 1; } if (AsmPlan_BLL.AddPlan(apo) > 0) { MessageBox.Show("保存成功!"); TB_PlanNumber.Text = ""; UD_ProductionNumber.Value = 1; TB_OperationUser.Text = ""; ReflshDataGridView(); } else { MessageBox.Show("保存失败,请检查输入信息是否正确!"); } } else { MessageBox.Show("输入信息不全,请检查后保存!"); } } else { MessageBox.Show("工单编号有重复!请重新输入"); }; }
/// <summary> /// button按钮的点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dGV_Print_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { string buttonText = this.dGV_Print.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (buttonText.Equals("生成条码") && (this.dGV_Print.Rows[e.RowIndex].DefaultCellStyle.BackColor != Color.Yellow)) { rTB_Barcode.Text = "";//清空richtextbox AsmPlanObject apo = new AsmPlanObject(); string plan_productionvr = dGV_Print.Rows[e.RowIndex].Cells["PRODUCTION_VR"].Value.ToString(); string plan_data = dGV_Print.Rows[e.RowIndex].Cells["DT"].Value.ToString(); string plan_lineid = dGV_Print.Rows[e.RowIndex].Cells["LINE_ID"].Value.ToString(); string plan_number = dGV_Print.Rows[e.RowIndex].Cells["NUMBER"].Value.ToString(); string plan_productionid = dGV_Print.Rows[e.RowIndex].Cells["PRODUCTION_ID"].Value.ToString(); string plan_id = dGV_Print.Rows[e.RowIndex].Cells["ID"].Value.ToString(); apo.ID = Convert.ToInt32(plan_id); apo.NAME = plan_productionvr; apo.PRODUCTION_ID = Convert.ToInt32(plan_productionid); apo.NUMBER = Convert.ToInt32(plan_number); apo.LINE_ID = Convert.ToInt32(plan_lineid); DateTime dt = Convert.ToDateTime(plan_data); //int numofdate =Convert.ToInt32(dt.ToString("MM-dd")); List <string> list = GetDayOfWeek(dt, plan_productionid); CreateBarcodeBysomething(list, dt, apo); ///设置R_PMS_PLAN_T打印标识 AsmPlan_BLL.SetBarcodeIdentification(plan_id); MessageBox.Show("条码生成成功!"); Thread.Sleep(1000); //dGV_Print.Rows[e.RowIndex] dGV_Print.DataSource = null; DataTable dtUpdate = AsmPlan_BLL.GetPlanObjectByConditionToPrint(); LoadSource(dtUpdate); } if (buttonText.Equals("展示条码") && (this.dGV_Print.Rows[e.RowIndex].DefaultCellStyle.BackColor == Color.Yellow)) { rTB_Barcode.Text = ""; DataTable dt = AsmPlanPrint_BLL.GetBarcodeByCondition(this.dGV_Print.Rows[e.RowIndex].Cells["ID"].Value.ToString()); for (int i = 0; i < dt.Rows.Count; i++) { rTB_Barcode.AppendText(dt.Rows[i]["SN"].ToString() + "\r"); } } } }
public static AsmPlanObject GetPlanObjectByCondition(string sql) { AsmPlanObject apo = AsmPlan_DAL.GetPlanObjectByCondition(sql); return(apo); }
public static int UpdatePlan(AsmPlanObject uo) { int a = AsmPlan_DAL.UpdatePlan(uo); return(a); }
public static int AddPlan(AsmPlanObject uo) { int a = AsmPlan_DAL.AddPlan(uo); return(a); }
/// <summary> /// 组合框事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { ComboBox combox = sender as ComboBox; //这里比较重要 // combox.Leave += new EventHandler(combox_Leave); try { //在这里就可以做值是否改变判断 if (combox.SelectedItem != null) { // ReflshDataGridView(); int row = DGV_Plan.SelectedRows[0].Index; if (combox.SelectedValue.ToString() == "0") { MessageBox.Show("计划已开始或已经是初始化,不能再初始化!"); combox.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged); ReflshDataGridView(); return; } else if (combox.SelectedValue.ToString() == "4" && Convert.ToInt32(planDt.Rows[row]["NUMBER"].ToString()) - Convert.ToInt32(planDt.Rows[row]["COMPLETE_NUMBER"].ToString()) > 0) { MessageBox.Show("计划没有完成,不能关闭计划!"); combox.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged); ReflshDataGridView(); return; } else if (combox.SelectedValue.ToString() == "4" && Convert.ToInt32(planDt.Rows[row]["NUMBER"].ToString()) - Convert.ToInt32(planDt.Rows[row]["COMPLETE_NUMBER"].ToString()) == 0) { combox.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged); #region >>>>>将运行时表中的数据转移到永久性表中 AsmPlanObject apo = AsmPlan_BLL.GetPlanObjectByCondition(" WHERE ID=" + Convert.ToInt32(planDt.Rows[row]["ID"].ToString())); AsmPPlanObject appo = new AsmPPlanObject(); appo.DT = System.DateTime.Now; appo.COMPLETE_FLAG = "4"; appo.COMPLETE_NUMBER = apo.COMPLETE_NUMBER; appo.CREATE_BARCODE_FLAG = apo.CREATE_BARCODE_FLAG; appo.LINE_ID = apo.LINE_ID; appo.NAME = apo.NAME; appo.NG_NUMBER = apo.NG_NUMBER; appo.NUMBER = apo.NUMBER; appo.OK_NUMBER = apo.OK_NUMBER; appo.OPREATION_USER = apo.OPREATION_USER; appo.PLAN_LEVEL = apo.PLAN_LEVEL; appo.PRODUCTION_ID = apo.PRODUCTION_ID; appo.REMAIND_NUMBER = apo.REMAIND_NUMBER; AsmPPlan_BLL.AddPPlan(appo); AsmPlan_BLL.DeleteRPlanByCondition(" ID=" + apo.ID); if (row < this.DGV_Plan.Rows.Count - 1) { for (int i = 0; i < this.DGV_Plan.Rows.Count - 1 - row; i++) { AsmPlanObject apoNext = AsmPlan_BLL.GetPlanObjectByCondition(" WHERE ID=" + Convert.ToInt32(planDt.Rows[row + i + 1]["ID"].ToString())); apoNext.PLAN_LEVEL = apo.PLAN_LEVEL + i; AsmPlan_BLL.UpdatePlan(apoNext); } } #endregion ReflshDataGridView(); return; } else if (combox.SelectedValue.ToString() == "3") { combox.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged); #region >>>>>将运行表中的数据转移到永久性表中 AsmPlanObject apo = AsmPlan_BLL.GetPlanObjectByCondition(" WHERE ID=" + Convert.ToInt32(planDt.Rows[row]["ID"].ToString())); AsmPPlanObject appo = new AsmPPlanObject(); appo.DT = System.DateTime.Now; appo.COMPLETE_FLAG = "3"; appo.COMPLETE_NUMBER = apo.COMPLETE_NUMBER; appo.CREATE_BARCODE_FLAG = apo.CREATE_BARCODE_FLAG; appo.LINE_ID = apo.LINE_ID; appo.NAME = apo.NAME; appo.NG_NUMBER = apo.NG_NUMBER; appo.NUMBER = apo.NUMBER; appo.OK_NUMBER = apo.OK_NUMBER; appo.OPREATION_USER = apo.OPREATION_USER; appo.PLAN_LEVEL = apo.PLAN_LEVEL; appo.PRODUCTION_ID = apo.PRODUCTION_ID; appo.REMAIND_NUMBER = apo.REMAIND_NUMBER; AsmPPlan_BLL.AddPPlan(appo); AsmPlan_BLL.DeleteRPlanByCondition(" ID=" + apo.ID); if (row < this.DGV_Plan.Rows.Count - 1) { for (int i = 0; i < this.DGV_Plan.Rows.Count - 1 - row; i++) { AsmPlanObject apoNext = AsmPlan_BLL.GetPlanObjectByCondition(" WHERE ID=" + Convert.ToInt32(planDt.Rows[row + i + 1]["ID"].ToString())); apoNext.PLAN_LEVEL = apo.PLAN_LEVEL + i; AsmPlan_BLL.UpdatePlan(apoNext); } } #endregion ReflshDataGridView(); return; } else { AsmPlanObject apo = AsmPlan_BLL.GetPlanObjectByCondition(" WHERE ID=" + Convert.ToInt32(planDt.Rows[row]["ID"].ToString())); apo.COMPLETE_FLAG = combox.SelectedValue.ToString(); AsmPlan_BLL.UpdatePlan(apo); combox.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged); ReflshDataGridView(); // DGV_Plan.ClearSelection(); // DGV_Plan.Rows[row].Selected = true; return; } } // Thread.Sleep(100); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 构建SN并存储 /// </summary> /// <param name="list_SN"></param> /// <param name="weekofyear"></param> /// <param name="lineid"></param> /// <param name="product_name"></param> /// <returns></returns> public bool CreateBarcodeBysomething(List <string> list_SN, DateTime numofdate, AsmPlanObject apo) { try { string month_day = ""; int str_month = Convert.ToInt32(numofdate.ToString("MM")); int str_day = Convert.ToInt32(numofdate.ToString("dd")); string month = ""; string day = ""; for (int i = 1; i < 32; i++) { if (str_month == i) { month = dic_month[i]; } if (str_day == i) { day = dic_month[i]; } } bool x = true; PrintManager pm = new PrintManager(); if (list_SN.Count != 0) { List <string> list_barcode = new List <string>(); List <int> list_lastnumoffive = new List <int>(); ///截取后五位 for (int i = 0; i < list_SN.Count; i++) { // list_lastnumoffive.Add(list_SN[i].ToString().IndexOf(list_SN[i].ToString(), 18, list_SN[i].ToString().Length)); int a = list_SN[i].ToString().Length; list_lastnumoffive.Add(Convert.ToInt32(list_SN[i].ToString().Substring(a - 7, 7))); } ///比较得出最大值 int max = list_lastnumoffive[0]; int max_keep = 0; for (int i = 0; i < list_lastnumoffive.Count; i++) { if (list_lastnumoffive[i] > max) { max = list_lastnumoffive[i]; max_keep = list_lastnumoffive[i]; } } DateTime dt = DateTime.Now; int year = Convert.ToInt32(dt.ToString("yyyy")); string str_year = ""; for (int i = 2017; i < 2051; i++) { if (i == year) { str_year = dic_year[i]; } } //int a = (dt.Year % 100) - 20; for (int i = 0; i < apo.NUMBER; i++) { max += 1; list_barcode.Add("0" + apo.LINE_ID + apo.NAME + str_year + month + day + max.ToString("D7")); } ///存储 /// for (int i = 0; i < list_barcode.Count; i++) { AsmPlanPrintObject appo = new AsmPlanPrintObject(); appo.DT = DateTime.Now; appo.SN = list_barcode[i].ToString(); rTB_Barcode.AppendText(appo.SN + "\r"); appo.PLAN_ID = apo.ID; appo.LINE_ID = Convert.ToInt32(apo.LINE_ID); appo.PRODUCTION_ID = Convert.ToInt32(apo.PRODUCTION_ID); appo.SERIAL_NO = max_keep + i; appo.PRINT_FLAG = "0"; AsmPlanPrint_BLL.AddPlanPrint(appo); } } else { List <string> list_barcode = new List <string>(); int numOfSN = Convert.ToInt32(apo.NUMBER); DateTime dtt = DateTime.Now; int year = Convert.ToInt32(dtt.ToString("yyyy")); string str_year = ""; for (int i = 2017; i < 2051; i++) { if (i == year) { str_year = dic_year[i]; } } for (int i = 1; i < numOfSN + 1; i++) { DateTime dt = DateTime.Now; string item = "0" + apo.LINE_ID + apo.NAME + str_year + month + day + i.ToString("D7"); list_barcode.Add(item); rTB_Barcode.AppendText(item.Trim() + "\r"); } ///存储 /// for (int i = 0; i < list_barcode.Count; i++) { AsmPlanPrintObject appo = new AsmPlanPrintObject(); appo.DT = DateTime.Now; appo.SN = list_barcode[i].ToString(); appo.PLAN_ID = apo.ID; appo.LINE_ID = Convert.ToInt32(apo.LINE_ID); appo.PRODUCTION_ID = Convert.ToInt32(apo.PRODUCTION_ID); appo.SERIAL_NO = i + 1; appo.PRINT_FLAG = "0"; AsmPlanPrint_BLL.AddPlanPrint(appo); } } return(x); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }