////料架与库别的二级联动,选择料架时触发 //protected void DropDownList_frame_key_SelectedIndexChanged(object sender, EventArgs e) //{ // try // { // DropDownList_return_sub_key.Items.Clear(); // string text = DropDownList_frame_key.SelectedValue.ToString(); // DataSet ds_return_sub_key = invoiceDC.getSubinventoryByFrame(text); // if (ds_return_sub_key != null) // { // DropDownList_return_sub_key.DataSource = ds_return_sub_key.Tables[0].DefaultView; // DropDownList_return_sub_key.DataValueField = "subinventory_key"; // DropDownList_return_sub_key.DataTextField = "subinventory_name"; // DropDownList_return_sub_key.DataBind(); // } // DropDownList_return_sub_key.Items.Insert(0, "--选择库别--"); // DropDownList_return_sub_key.SelectedIndex = 1; // } // catch (Exception e2) // { // PageUtil.showToast(this, "料架与库别二级联动失败,请检查是否有关联数据"); // return; // } //} //生成一个退料单单据号 protected void NewInvoice_no(object sender, EventArgs e) { string strInvoice_no = invoice_no.Value; if (!string.IsNullOrWhiteSpace(strInvoice_no)) { PageUtil.showToast(this, "单据号已生成,请勿重复操作!"); return; } int end; string end_text; string month = string.Empty; string year = string.Empty; DataSet ds; ds = invoiceDC.getTheNewestReturnHeaderByCreatetime(); //判断数据库是否有数据,没有数据则初始化一个流水号 if (ds == null) { end_text = "00001"; month = DateTime.Now.Month.ToString(); year = DateTime.Now.Year.ToString(); //为月份补0 for (int i = month.Length; i < 2; i++) { month = "0" + month; } //截取年份后两位 year = year.Substring(2, 2); } else { //end = int.Parse(ds.Tables[0].Rows[0]["return_header_id"].ToString()); //截取上一个单号的后5位,即从第5位开始的5位(0开始增) string sInvoice_no = ds.Tables[0].Rows[0]["invoice_no"].ToString(); string result = sInvoice_no.Substring(5, 5); end = int.Parse(result); string last_month = sInvoice_no.Substring(3, 2); string last_year = sInvoice_no.Substring(1, 2); ////判断id是否为99998,是则取下一个流水号为99999,否则取余+1作为下一个流水号 //end = end % 99998 == 0 ? 99998 + 1 : end % 99999 + 1; //当end为99999时,重置从1开始计数。否则,递增 if (end == 99999) { end = 1; } else { end = end + 1; } end_text = end.ToString(); //为流水号补0 for (int i = end_text.Length; i < 5; i++) { end_text = "0" + end_text; } month = DateTime.Now.Month.ToString(); year = DateTime.Now.Year.ToString(); year = year.Substring(2, 2); for (int i = month.Length; i < 2; i++) { month = "0" + month; } //新月份或新的一年,从1重新计数 if (month != last_month) { end_text = "00001"; } if (year != last_year) { end_text = "00001"; } } invoice_no.Value = "F" + year + month + end_text; }