Beispiel #1
0
        /// <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");
                    }
                }
            }
        }
Beispiel #2
0
        /// <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);
            }
        }