Esempio n. 1
0
    /// <summary>
    /// 插入或更新一条宴请申请记录
    /// </summary>
    /// <param name="id"></param>
    /// <param name="ei"></param>
    public static void SetEntertainApplyByID(int id, EntertainApply ei)
    {
        SqlConnection conn = new SqlConnection(connString);
        SqlCommand    cmd;
        bool          isExist = HasEntertainApplyInfo(id);

        if (isExist)
        {
            cmd = new SqlCommand("UPDATE [EntertainApplies] SET [StafffName] = @StaffName, [Departments] = @Departments, [Manager] = @Manager, [ApplyDate] = @ApplyDate, [TreatDate] = @TreatDate, [Reason] = @Reason, [Treated] = @Treated, [Budget] = @Budget,[TreatStandard]=@TreatStandard, [TreatStyle] = @TreatStyle, [ApproveProcess] = @ApproveProcess WHERE [ApplyID] = @ApplyID", conn);
        }
        else
        {
            cmd = new SqlCommand("INSERT INTO [EntertainApplies] ([StaffName], [Department], [ApplyDate],[TreatDate],[Manager],[Reason],[Treated],[Budget],[TreatStandard], [TreatStyle],[ApproveProcess]) VALUES (@StaffName, @Department, @ApplyDate,@TreatDate,@Manager,@Reason,@Treated,@Budget,@TreatStandard, @TreatStyle,@ApproveProcess)", conn);
        }

        cmd.Parameters.Add("@StaffName", SqlDbType.VarChar).Value      = ei.staffName;
        cmd.Parameters.Add("@Department", SqlDbType.VarChar).Value     = ei.department;
        cmd.Parameters.Add("@Manager", SqlDbType.VarChar).Value        = ei.manager;
        cmd.Parameters.Add("@ApplyDate", SqlDbType.DateTime).Value     = ei.applyDate;
        cmd.Parameters.Add("@TreatDate", SqlDbType.DateTime).Value     = ei.treatDate;
        cmd.Parameters.Add("@TreatStandard", SqlDbType.VarChar).Value  = ei.treatStandard;
        cmd.Parameters.Add("@Reason", SqlDbType.VarChar).Value         = ei.reason;
        cmd.Parameters.Add("@Treated", SqlDbType.VarChar).Value        = ei.treated;
        cmd.Parameters.Add("@Budget", SqlDbType.Float).Value           = ei.budget;
        cmd.Parameters.Add("@TreatStyle", SqlDbType.VarChar).Value     = ei.treatStyle;
        cmd.Parameters.Add("@TreatStandard", SqlDbType.VarChar).Value  = ei.treatStandard;
        cmd.Parameters.Add("@ApproveProcess", SqlDbType.VarChar).Value = ei.approveProcess;

        conn.Open();

        //同时在标准化申请表中插入一条记录
        int recordId = Convert.ToInt32(cmd.ExecuteScalar());

        if (!isExist)
        {
            SqlCommand cmd2 = new SqlCommand("INSERT INTO [AllApplies] ( [ApplyStaff], [ApplyDate], [ApplyType], [NextApprover], [RecordID], [Result]) VALUES (@ApplyStaff, @ApplyDate, @ApplyType, @NextApprover, @RecordID, @Result)", conn);
            cmd2.Parameters.Add("@ApplyStaff", SqlDbType.VarChar).Value   = ei.staffName;
            cmd2.Parameters.Add("@ApplyDate", SqlDbType.DateTime).Value   = DateTime.Now;
            cmd2.Parameters.Add("@ApplyType", SqlDbType.VarChar).Value    = "宴请申请";
            cmd2.Parameters.Add("@RecordID", SqlDbType.Int).Value         = recordId;
            cmd2.Parameters.Add("@NextApprover", SqlDbType.VarChar).Value = BasicInfo.GetOrganizationResponsible();
            cmd2.Parameters.Add("@Result", SqlDbType.Bit).Value           = false;
            cmd2.ExecuteNonQuery();
        }

        conn.Close();
    }