コード例 #1
0
        /// <summary>
        /// 联机任务
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="meno"></param>
        /// <param name="station"></param>
        /// <returns></returns>
        public string SaveDolist(DataTable dt, string meno, InOutType type)
        {
            int result = 0;

            DbConnection conn = dbHelper.getConnection();

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                Log.write(ex.Message + "\r\n" + ex.StackTrace);
                conn.Close();
                throw ex;
            }
            DbTransaction tran = conn.BeginTransaction();
            DbCommand     com  = conn.CreateCommand();
            string        sql  = string.Empty;

            try
            {
                com.Transaction = tran;

                string   dh;
                DateTime dtNow  = DateTime.Now;
                long     dec_id = 0;
                string   c_id   = string.Empty;
                sql = "SELECT MAX(c_id) FROM T_OPERATE_INOUT_MAIN where datediff(day,[D_TIME],getdate()) = 0 AND C_CRK_LEIBIE = '" + (int)type + "'";

                com.CommandText = sql;
                object obj = com.ExecuteScalar();
                dec_id = Convert.IsDBNull(obj) ? 0 : Convert.ToInt64(obj.ToString().Substring(10));
                c_id   = Common.GetInOutCode(type) + dtNow.ToString("yyyyMMdd") + (dec_id + 1).ToString().PadLeft(6, '0');
                dh     = c_id;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sql             = @"INSERT INTO [T_Runing_Dolist]([Dec_ID], [C_DH],  [I_INOUT], [D_RQ], [C_MATERIEL], 
                            [C_PLACE], [DEC_COUNT],  [C_CZY], [I_RUN], [D_AddRQ], [C_MEMO], [I_FLAG], [C_MACHINE])
                            VALUES(@Dec_ID, @C_DH, @I_INOUT, @D_RQ, @C_MATERIEL, @C_PLACE, @DEC_COUNT, @C_CZY, @I_RUN, @D_AddRQ, @C_MEMO, @I_FLAG, @C_MACHINE)";
                    com.CommandText = sql;

                    Hashtable table2 = new Hashtable();
                    table2.Add("Dec_ID", i + 1);
                    table2.Add("C_DH", dh);
                    table2.Add("I_INOUT", (int)type);
                    table2.Add("D_RQ", Convert.ToDateTime(dt.Rows[i][5]).ToString("yyyy-MM-dd"));
                    table2.Add("C_MATERIEL", dt.Rows[i][0]);
                    table2.Add("C_PLACE", dt.Rows[i][4]);
                    table2.Add("DEC_COUNT", dt.Rows[i][3]);
                    table2.Add("C_CZY", dt.Rows[i][6]);
                    table2.Add("I_RUN", 0);
                    table2.Add("D_AddRQ", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                    if (meno == null || string.Empty.Equals(meno.Trim()))
                    {
                        table2.Add("C_MEMO", DBNull.Value);
                    }
                    else
                    {
                        table2.Add("C_MEMO", meno);
                    }

                    if (type.Equals(InOutType.KNIFE_OUT_USE))
                    {
                        table2.Add("I_FLAG", 1);
                        table2.Add("C_MACHINE", dt.Rows[i][7]);
                    }
                    else
                    {
                        table2.Add("I_FLAG", 0);
                        table2.Add("C_MACHINE", DBNull.Value);
                    }

                    DbParameter[] parms2 = dbHelper.getParams(table2);
                    com.Parameters.Clear();
                    com.Parameters.AddRange(parms2);
                    result = com.ExecuteNonQuery();
                }

                tran.Commit();

                if (result > 0)
                {
                    return(dh);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                tran.Rollback();
                conn.Close();
                Log.write(ex.Message + "\r\n" + ex.StackTrace);
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }