//--------------------------------------------------------// // Method //--------------------------------------------------------// public string NumberingOrder(string officeCode, string department) { string orderNo = department; if (officeCode != "H") { orderNo = "A"; } orderNo += util.TruncateByteRight(Convert.ToString(DHandling.FiscalYear(DateTime.Today)), 2); orderNo += officeCode; SqlHandling sh = new SqlHandling("M_Office"); DataTable dt = sh.SelectAllData("WHERE OfficeCode = '" + officeCode + "'"); if (dt == null) { return(null); } DataRow dr; dr = dt.Rows[0]; int orderSeqNo = Convert.ToInt32(dr["OrderSeqNo"]); orderSeqNo++; orderNo += orderSeqNo.ToString("000"); if (!office_Update(officeCode, orderSeqNo)) { return(null); } return(orderNo); }
public string CreateTaskBaseCode(string officeCode) { int seqNo = 0; string taskBaseCode = ""; string selectSql = "SELECT OrderSeqNo FROM M_Office WHERE OfficeCode = @oCod"; string updateSql = "UPDATE M_Office SET OrderSeqNo = @oSeq WHERE OfficeCode = @oCod"; using (TransactionScope tran = new TransactionScope()) using (SqlConnection conn = new SqlConnection(ConnectionString)) { try { conn.Open(); SqlCommand cmd = new SqlCommand(selectSql, conn); cmd.Parameters.Add("@oCod", SqlDbType.Char); SqlCommand cmd1 = new SqlCommand(updateSql, conn); cmd1.Parameters.Add("@oCod", SqlDbType.Char); cmd1.Parameters.Add("@oSeq", SqlDbType.Int); cmd.Parameters["@oCod"].Value = officeCode; SqlDataReader dr = TryExReader(conn, cmd); if (!dr.HasRows) { return(null); } while (dr.Read()) { seqNo = Convert.ToInt32(dr["OrderSeqNo"]); } dr.Close(); cmd1.Parameters["@oCod"].Value = officeCode; seqNo++; cmd1.Parameters["@oSeq"].Value = seqNo; if (TryExecute(conn, cmd1) < 0) { return(null); } } catch (SqlException sqle) { MessageBox.Show("SQLエラー errorno " + Convert.ToString(sqle.Number) + " " + sqle.Message); conn.Close(); return(null); } conn.Close(); tran.Complete(); } DateTime nowdt = DateTime.Now; taskBaseCode = (DHandling.FiscalYear(nowdt) - 2000).ToString() + officeCode + seqNo.ToString("000"); return(taskBaseCode); }